Click here to Skip to main content
15,793,019 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more: (untagged)
Question 1: I have a Model that has an 'Active' property. The 'Active' property's value is a char either 'Y' or "N". I am going to use either a radio button helper of a checkbox helper. What is the best way to implement this?

Question 2: (more difficult): Now, since we are using an Oracle database the Models 'User Access' property, which in C# is an Enum, is a decimal (0.0 ,1.0, 2.0) and not an integer. The Enum looks like this:

enum APPRole {SimpleUser, AdvancedUser, ExpertUser};

Now, how do I use a helper dropdown to use my Model's 'User Access' decimal data property to compare to the enum and then display strings of the appropriate role?

Big Thanks!

Steve Holdorf

1 solution

  1. Who told you this data type should be a character?

    If you think that the UI should show 'Y' or 'N', it does not mean that this should be your type.

    The type char has too many values, but you need the type which has only two values. The best type for that is bool; another option would be enumeration type with two values. But bool is still better. You can always map it onto a set of two strings (why not "Yes" and "No"?) or anything else you would need to your UI.

    Generally, thoroughly isolate UI from other aspects of your project. Roughly speaking, this what is MVC is designed for.
  2. The adequate enumeration type would be:
    enum APPRole : byte {
       SimpleUser    = 0,
       AdvancedUser  = 1,
       ExpertUser    = 2,

    By coincidence, even if you omitted those integer values, the default rules for underlying integer values for enumeration members would give you the same values.

    Now, nothing prevents you from working decimal values (I have no idea why would you need them, but let's assume you are right, even though I doubt it; if you explain why do you need those 0.0, 1.0, and 2.0 values, we can discuss it.) You have everything. The statements like this one will give you correct assignment and correct comparison:
    decimal simpleUser = (byte)APPRole.SimpleUser;
    decimal value = //...
    if (value == (byte)APPRole.SimpleUser) { /* ... */ }

    And so on…

Share this answer
Stephen Holdorf 9-Jul-14 4:46am    
Your solution about the radio button was great; however, if you could look at another approach and see if I could make that work without changing the EF model that would be great!

Also, if you have any advise on the actual wire up of controller save and delete (only setting the ACTIVE char to 'N') that would also be helpful. Thanks! And big fan.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900