Reputation: 1200
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.
Upvotes: 2
Views: 5135
Reputation: 887225
You can store the descriptions in a Dictionary<CategoryList, string>
somewhere and write @Html.Raw(YourDictionary[Model.Category])
Upvotes: -1