Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7418353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:52:14+00:00 2026-05-29T07:52:14+00:00

I have a @model MyModel on a razor view. I know if I have

  • 0

I have a @model MyModel on a razor view. I know if I have a FirstName string defined in MyModel with a

[Display(Name = "First Name:")]

property, that I can use

@Html.LabelFor(m => m.FirstName, new { @class = "mylabelstyle", title = "Enter first name." })

I am using radio button lists with code such as the following:

[Required(ErrorMessage = "Please tell us how you heard of us.")]
        [Display(Name = "How did you hear about us?")]
        public ReferralList Referral { get; set; }
        public enum ReferralList
        {
            Referral_Google,
            Referral_OtherSearch,
            Referral_Website,
            Referral_Friend,
            Referral_Television,
            Referral_Radio,
            Referral_Other
        }
        public class ReferralDictionary
        {
            public static readonly Dictionary<ReferralList, string> referralDictionary = new Dictionary<ReferralList, string>
            {
                { ReferralList.Referral_Google, "Google" },
                { ReferralList.Referral_OtherSearch, "Bing / Yahoo / AOL" },
                { ReferralList.Referral_Website, "Website1.com / Website2.com" },
                { ReferralList.Referral_Friend, "Friend / Relative / Co-worker" },
                { ReferralList.Referral_Television, "Television" },
                { ReferralList.Referral_Radio, "Radio" },
                { ReferralList.Referral_Other, "Other" },
            };
            static string ConvertReferral(ReferralList referrallist)
            {
                string name;
                return (referralDictionary.TryGetValue(referrallist, out name))
                    ? name : referrallist.ToString();
            }

            static void Main()
            {
                Console.WriteLine(ConvertReferral(ReferralList.Referral_Google));
                Console.WriteLine(ConvertReferral(ReferralList.Referral_OtherSearch));
                Console.WriteLine(ConvertReferral(ReferralList.Referral_Website));
                Console.WriteLine(ConvertReferral(ReferralList.Referral_Friend));
                Console.WriteLine(ConvertReferral(ReferralList.Referral_Television));
                Console.WriteLine(ConvertReferral(ReferralList.Referral_Radio));
                Console.WriteLine(ConvertReferral(ReferralList.Referral_Other));
            }
        }

I do the above so that in a confirm page I can do something like:

<div class="display-label">
     Referred From:
</div>
<div class="display-field">
     @Html.Raw(MyNamespace.Models.MyModel.ReferralDictionary.referralDictionary[Model.Referral])
</div>

which outputs the selection (say, “Google”) for example.

The above code is working, so if I mistyped something that’s not my problem.

My problem is that in my razor view, I have am doing this:

<td class="radio_cell">
    @Html.LabelFor(m => m.Referral, new { @class = "mylabelstyle", title = "How did you learn about our services?." })
</td>
<td>
    <span class="radio_validation">@Html.ValidationMessageFor(m => m.Referral)</span>
    <div class="radio">
        <p>
            @Html.RadioButtonFor(m => m.Referral, "Referral_Google")
            Google
        </p>
        <p>
            @Html.RadioButtonFor(m => m.Referral, "Referral_OtherSearch")
            Bing / Yahoo / AOL
        </p>
        <p>
            @Html.RadioButtonFor(m => m.Referral, "Referral_Website")
            Website1.com / Website2.com
        </p>
        <p>
            @Html.RadioButtonFor(m => m.Referral, "Referral_Friend")
            Friend / Relative / Co-worker
        </p>
        <p>
            @Html.RadioButtonFor(m => m.Referral, "Referral_Television")
            Television
        </p>
        <p>
            @Html.RadioButtonFor(m => m.Referral, "Referral_Radio")
            Radio
        </p>
        <p>
            @Html.RadioButtonFor(m => m.Referral, "Referral_Other")
            Other
        </p>
    </div>
</td>

If you notice, I am putting, for example, “Google” as text in the model class, and writing out “Google” again in the view.

For one word this is not a big deal (nor for one radio button list). However, I am using a lot of radio button lists, and many of my choices are short sentences. So, keeping the view and the model class text in “synch” is starting to become a nightmare when I make changes.

I tried using the @Html.Raw to output the individual dictionary item with no success. So I am stuck.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:52:18+00:00Added an answer on May 29, 2026 at 7:52 am

    I think this can help: http://jonlanceley.blogspot.com/2011/06/mvc3-radiobuttonlist-helper.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model public class MyModel { public string Name { get; set;} }
I have a Model that looks like: class MyModel(Model): name = models.TextField(blank=True, default='') bio
Let's say I have a controller action defined as: public ActionResult(MyModel model, string someParameter)
I have a model that contains a collection, such as this: class MyModel {
I have a simple Model: public class MyModel { public string Text{get;set;} } I
hejdig. In Aspnetmvc2 I have a model object that I send to a View.
Someone inputs www.example.com/3/ I have a model with a charfield that I can slugify.
I have a model with CharField() class MyModel(models.Model) field = models.CharField(...) How can I
I have a model MyModel that has a field expiration_datetime. Every time a user
I have a model with an optional file field class MyModel(models.Model): name = models.CharField(max_length=50)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.