2

I am using RadioButtonFor to display a list of selectable items. It's part of a wizard I am using, and the last step of the wizard is a summary for the user to confirm their submission. I have everything working except for the RadioButtonFor. My summary contains something pretty basic showing what the user input.

Example:

...

<div>Summary</div>

<div>Please confirm the information you are submitting.</div>

<div>First Name: @Model.FirstName</div>

...

The relevant portion of my model:

public CategoryList Category { get; set; }

public enum CategoryList
{
    Category1
    Category2
    Category3
}

The relevant portion of my page (wizard step with RadioButtonFor):

...

@Html.LabelFor(m => m.Category, new { @class = "CLASS" })
@Html.ValidationMessageFor(m => m.Category)

<div>
@Html.RadioButtonFor(m => m.Category, "Category1")
<span>NEW!</span>Category 1. This Category is for BLAH BLAH BLAH ...
@Html.RadioButtonFor(m => m.Category, "Category2")
Category 2. This Category is for BLAH BLAH BLAH ...
@Html.RadioButtonFor(m => m.Category, "Category3")
Category 3. This Category is for BLAH BLAH BLAH ...
</div>
...

The relevant portion of my page (wizard summary step containing RadiouButtonFor):

<div>@Model.Category</div>

The above simply displays the actual name in Category List, say "Category1" if the user selected Category 1, so I know I have the enum working correctly. However, I want the description to be, well, more descriptive. Say that I want Category1 to say "Category 1. This category is for BLAH BLAH BLAH" as well as to maybe put a around "Category 1." So that it is displayed in RED. The actual name I use in the enum is three words, and contains two underscores, so it's not very UI friendly to have "Word1_Word2_Word3" in there, which is what displays in the summary.

To be more precise, if you look at the relevant portion of the page above which contains the RadioButtonFor, I include text for the radio button which shows to the user on the UI. The text that appears there is what I want to appear in the summary.

I tried using the following:

<div>@Model.Category.CategoryList</div>

but it throws an error (...does not contain a definition for "CategoryList" and no extension method "CategoryList" accepting a first argument of type ... could be found (are you missing a using directive or assembly reference"). I've spent hours on the googlenet, and could not find anything (quite possibly because I am not formulating good search terms).

Any thoughts? Is this possible, or is there something alternative I can do to achieve what I am looking for?

Again, I appreciate any help and sorry if re-asking in a different way is against policy.

Patrick
  • 1,717
  • 7
  • 21
  • 28
REMESQ
  • 1,190
  • 2
  • 26
  • 60
  • There's nothing wrong with deleting and re-asking a poorly-formulated question. However, your question is still unclear. – SLaks Apr 28 '11 at 17:38
  • Not sure how you mean. I am basically trying to show a summary page with the user input. If user picks RadioButton 1, and I am using an ENUM, it will only display the name in the ENUM. I want it to display text that I describe for whatever RadioButton is selected, rather than what is in the ENUM. Sorry if not too clear. – REMESQ Apr 28 '11 at 17:52

1 Answers1

-1

You can store the descriptions in a Dictionary<CategoryList, string> somewhere and write @Html.Raw(YourDictionary[Model.Category])

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Ah! I found something on the googlenet about the Dictionary<> but could not implement it properly. Also, that @Html.Raw portion was not part of what I found, so that may actually get it to work. Hopefully I can create that. Thanks! Will report back on my results. – REMESQ Apr 28 '11 at 18:04
  • I am getting the "YourDictionary" name doesn't exist in the current context here (where "YourDictionary") is the name of my dictionary. – REMESQ Apr 28 '11 at 21:05
  • 1
    If the dictionary is a static property, you need to access it through its containing class. – SLaks Apr 28 '11 at 21:31
  • That last comment led me in the right direction. Problem was I ignored intellisence, which had me insert the ENTIRE thing of Namepace.Models.ViewModel.Class.Dictionary. But that all did the trick, and now I can see the content of the dictionary. Thanks! – REMESQ Apr 28 '11 at 21:45
  • You may want to `@using` the namespace. – SLaks Apr 28 '11 at 22:47
  • This is a proper solution here: http://stackoverflow.com/questions/5621013/pass-enum-to-html-radiobuttonfor-mvc3 – Doguhan Uluca Sep 11 '12 at 13:56