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

  • Home
  • SEARCH
  • 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 7024537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:51:10+00:00 2026-05-27T23:51:10+00:00

I am using a model in MVC3 to populate textboxes on my page like

  • 0

I am using a model in MVC3 to populate textboxes on my page like so :

<input name="test" value="a" type="radio" id="emp_contributions_gbp" @if (Model.myvalue.ToString() == "x"){<text>checked=true</text>}>

This works perfectly fine for saying – “if model.myvalue = x, then check this box”

However, I want to be able to return this model to the controller so I can persist the data should it be updated.

I am now using:
@Html.TextBoxFor(m => m.someField) which works perfectly with the model, however I have no idea how I could use .CheckboxFor and my IF statements together

  • 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-27T23:51:11+00:00Added an answer on May 27, 2026 at 11:51 pm

    You can use the CheckBoxFor method like so:

    @Html.CheckBoxFor(m => m.SomeProperty, new { checked = Model.myvalue.ToString() == "x" })
    

    See here for the MSDN documentation of this overload.

    Update

    Consider using the RadioButtonFor method instead:

    Model:

    public class MyViewModel
    {
      [Required]
      public string SomeProperty { get; set; }
    }
    

    View:

    @using (Html.BeginForm())
    {
      <div>A: @Html.RadioButtonFor(x => x.SomeProperty, "a")</div>
      <div>B: @Html.RadioButtonFor(x => x.SomeProperty, "b")</div>
      <div>C: @Html.RadioButtonFor(x => x.SomeProperty, "c")</div>
      <input type="submit" />
    }
    

    You can then preselect some radio by setting the view model property to the corresponding value:

    public ActionResult Index()
    {
      var model = new MyViewModel
      {
        SomeProperty = "a" // select the first radio
      };
      return View(model);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the Model-View-Presenter pattern for a web page. Should the presenter be
I am using custom model binder in ASP.NET MVC 2 that looks like this:
I use EntityFramework CodeFirst MVC3. In my model I defined a nullable property like
I am using MVC3 and displaying my data in a webgrid. I would like
I am trying to render the following HTML using an MVC3 Razor View: <input
I'm using MVC3 w/ Razor and I have a model that has quite a
I'm working with MVC3, and using Entity Framework 4.0 Entities as my model. So
I’ve got an unexpected situation when using Remote Attribute in ASP.NET MVC3. The model
Using MVC3 and Entity Framework. Am trying to get validation flowing from data model
I am using jqgrid (standard) with EF 4 + MVC3 . I'd like to

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.