Translate

Thursday 26 September 2013

Multiple Radio Button List in Asp.Net MVC3 or MVC4 Using Enum Or Muliple Radio Button List Using Selected List Iems

Multiple Radio Button List in Asp.Net MVC3 or MVC4 Using Enum

Hi Developers,

I going to show the Mutiple RadioButton List MVC3 using  Enum .How To show and save the particular radio button value in data base.



Model Property :

public BowlerType? BowlerActive { get; set; }

public enum BowlerType
    {
        FastMedium,
        LegSpinner,
        MediumPace,
        OffSpinner
    }



 Employeee Controller :

Here I’m creating a list of items for  Multiple radio button list and returning.
private List<SelectListItem> BowlerActive()
        {
            var opt = new List<SelectListItem>();
            opt.Add(new SelectListItem { Value = "Fast Medium", Text = "Fast Medium" });
            opt.Add(new SelectListItem { Value = "Leg Spinner", Text = "Leg Spinner" });
            opt.Add(new SelectListItem { Value = "Medium Pace", Text = "Medium Pace" });
            opt.Add(new SelectListItem { Value = "Off Spinner", Text = "Off Spinner" });
            return opt;
        }



Suppose if want to create a some data regarding players type details. In Controller directly u can assign into a some ViewData or ViewBag or Session. so here I’m showing using ViewData how to bind into particular list of items.


So now I’m going to show the view how to retrieve the Radio Button gender list.
View  :

@Html.RadioButtonFor(x => x.BowlerActive, "FastMedium")
@Html.RadioButtonFor(x => x.BowlerActive, "LegSpinner")
@Html.RadioButtonFor(x => x.BowlerActive, "MediumPace")
@Html.RadioButtonFor(x => x.BowlerActive, "OffSpinner")



Or Else

ViewData["BowlerActiveList "] = new SelectList(BowlerActive (), "Value", "Text");



@foreach (var item in (IEnumerable<SelectListItem>)ViewData["BowlerActiveList"])
                           {
                           <ul>
                           @Html.RadioButtonFor(model => model.BowlerActive, new { @item.Value, @item.Text })
                           <label for = @item.Value> @item.Text</label>
                           </ul>
                           }



Note :  when you are saving the Enum Type, before we need to convert into Enum parse. Ex :    BowlerActive = (BowlerType)Enum.Parse(typeof(BowlerType),str),


 Happy Coding...

  Jagan Mohan




Radio Button List in Asp.Net MVC3 or MVC4 or Binding Radio Button List

Radio Button List in Asp.Net MVC3 or MVC4

Hi Developers,

I going to show the RadioButton List MVC3.How To bind and show the list in a view.



Model Property :

public string Gender { get; set; }


 Employeee Controller :

Here I’m creating a list of items to bind in drop down list and returning.
private List<SelectListItem> EmployeeGender()
        {
            var options = new List<SelectListItem>();
            options.Add(new SelectListItem { Value = "Male", Text = " Male" });
            options.Add(new SelectListItem { Value = "FeMale", Text = " FeMale " });    

            return options;
        }




Suppose if want to create a some data regarding employee gender details. In Controller directly u can assign into a some ViewData or ViewBag or Session. so here I’m showing using ViewData how to bind into particular list of items.
In contoroller u can call the method and assign into a ViewDate like this :

ViewData["EmpGender"] = new SelectList(EmployeeGender (), "Value", "Text", Model Property Name);



So now I’m going to show the view how to retrieve the Radio Button gender list.
View  :

@Html.RadioButtonFor(model => model.BatActive, "Male", true)Male
@Html.RadioButtonFor(model => model.BatActive, " FeMale ", true)Female



 Happy Coding...

  Jagan Mohan


Drop Down List in MVC3 or MVC4 Or Binding Dropdown List MVC3

Drop Down List in Asp.Net MVC3 or MVC4

Hi Developers,

I going to show the Dropdown List MVC3. How To bind and show the list in a view.



Model Property :

public string Empdomian { get; set; }


 Employeee Controller :

Here I’m creating a list of items to bind in drop down list and returning.
private List<SelectListItem> EmployeeDomainList()
        {
            var options = new List<SelectListItem>();
            options.Add(new SelectListItem { Value = "Programmer", Text = " Programmer" });
            options.Add(new SelectListItem { Value = "Designer", Text = " Designer " });
          options.Add(new SelectListItem { Value = "Tester", Text = " Tester " });
          options.Add(new SelectListItem { Value = "DBA", Text = " DBA " });
     options.Add(new SelectListItem { Value = "NetworkAdmin", Text = " NetworkAdmin " });

            return options;
        }




Suppose if want to create a some data regarding employee details. In Controller directly u can assign into a some ViewData or ViewBag or Session. so here I’m showing using ViewData how to bind into particular list of items.
In contoroller u can call the method and assign into a ViewDate like this :

ViewData["EmpList"] = new SelectList(EmployeeDomainList(), "Value", "Text");



So now I’m going to show the view how to retrieve the drop down list binding data.

View  :

@Html.DropDownListFor(model => model. Empdomian, (IEnumerable<SelectListItem>)ViewData["EmpList "], "Select")




 Happy Coding,,,,,,

Jagan Mohan