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 6987285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:55:01+00:00 2026-05-27T18:55:01+00:00

Given I have a Model object like … public class MyModel { public int

  • 0

Given I have a Model object like …

public class MyModel
{
  public int SomeProperty { get; set; }
  public int SomeOtherProperty { get; set; } 

  public IList<DeliveryDetail> DeliveryDetails { get; set; }
}

public DeliveryDetail
{
   public string Description { get; set; }
   public bool IsSelected { get; set; }
}

and I pass it through to a View like this …

// Controller
public ActionResult Index()
{
  MyModel myModel = Factory.CreateModelWithDeliveryDetails(x);
  return View(myModel);
}

How would I render / bind a set of radio buttons (in the view)? Using the following code doesn’t post the data back:

@foreach(var deliveryDetail in @Model.DeliveryDetails)
{
   @deliveryDetail.Description
   @Html.RadioButtonFor(x => deliveryDetail, false)
}
  • 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-27T18:55:02+00:00Added an answer on May 27, 2026 at 6:55 pm

    Selections in a radio button list are mutually exclusive. You can select only a single value. So binding a radio button list to a property of type IEnumerable doesn’t make any sense. You probably need to adapt your view model to the requirements of the view (which in your case is displaying a radio button list where only a single selection can be made). Had you used a checkbox list, binding to an IEnumerable property would have made sense as you can check multiple checkboxes.

    So let’s adapt the view model to this situation:

    Model:

    public class MyModel
    {
        public string SelectedDeliveryDetailId { get; set; }
        public IList<DeliveryDetail> DeliveryDetails { get; set; }
    }
    
    public class DeliveryDetail
    {
       public string Description { get; set; }
       public int Id { get; set; }
    }
    

    Controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var model = new MyModel
            {
                DeliveryDetails = new[]
                {
                    new DeliveryDetail { Description = "detail 1", Id = 1 },
                    new DeliveryDetail { Description = "detail 2", Id = 2 },
                    new DeliveryDetail { Description = "detail 3", Id = 3 },
                }
            };
            return View(model);
        }
    
        [HttpPost]
        public ActionResult Index(MyModel model)
        {
            // Here you will get the id of the selected delivery detail
            // in model.SelectedDeliveryDetailId
            ...
        }
    }
    

    View:

    @model MyModel
    
    @using (Html.BeginForm())
    {
        foreach (var deliveryDetail in Model.DeliveryDetails)
        {
           @deliveryDetail.Description
           @Html.RadioButtonFor(x => x.SelectedDeliveryDetailId, deliveryDetail.Id)
        }
        <button type="submit">OK</button>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given you have the following class (bad C#, but you get the drift): public
I have an object model that looks like this (pseudo code): class Product {
When I have a given django model class like this: class BaseClass(models.Model): some_field =
Given I have a class with two constructors: public class TestClass { ObjectOne o1;
So I have an MVC action with the header: public PartialViewResult PersistPlaceholderItems(ModelObject model, int
I have a constructor signature that looks like this. public LocateEditorViewModel( ILocateRepository locateRepository, int
given a string identifying a Django model I have to obtain the associated object
Let's say you have this Model: //model public class Stuff { public string Name
My object model is given below and would like your inputs on the number
Given two model classes, Foo and Bar , I want Foo to have 3

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.