Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc radio button list

Tags:

asp.net-mvc

I am trying to display a list of radio buttons for a list of values in ASP.NET MVC. I am confused on how to write the model for the radio button list and the view to be displayed. I need to display a static list of values.

Can some please help.

Thanks.

like image 773
Jake Avatar asked Aug 23 '11 20:08

Jake


People also ask

What is radio button list in asp net?

The DevExpress ASP.NET Radio Button List (ASPxRadioButtonList) editor is a radio button group that allows end-users to select a single item at a time. Its contents can be generated dynamically by binding the editor to a data source. You can also create items explicitly by populating the Items collection manually.


1 Answers

i'm implementing values on viewModel you can take it from model if you want

viewModel

    public class PropMgmtViewModel
{
    public Property Property { get; set; }
    public IEnumerable<Property> Properties { get; set; }
    public SelectList Cities { get; private set; }


    static Dictionary<int, string> CitiesDict = new Dictionary<int, string>()
{
    { 1 ,"Chicago"},
    { 2 ,"New York"},
    { 3 ,"Zimbabwe"},
};
    public PropMgmtViewModel()
    {
        Cities = new SelectList(CitiesDict, "Key", "Value");
    }

view code i also included the seleclist propert to show you how it's done

 @foreach (var radioitem in Model.Cities)
    {
        @radioitem.Text;
    @Html.RadioButtonFor(model => model.Property.City, radioitem.Value);
    }
        @Html.DropDownListFor(model => model.Property.City, Model.Cities,"Seciniz") 
like image 162
c0demaster Avatar answered Oct 27 '22 21:10

c0demaster