Code to render a RadioButton list in Asp.Net MVC

Goud.Kv
Posted by Goud.Kv under ASP.NET MVC category on | Points: 40 | Views : 3565
Below code snippet renders the RadioButtonlist in the view of your application.

Type below code in your Razor view,

@Html.RadioButtonList("Categories", new List<SelectListItem>

{

new SelectListItem {Text = "Item 1", Value = "1", Selected = true},

new SelectListItem {Text = "Item 2", Value = "2"},

new SelectListItem {Text = "Item 3", Value = "3"},

new SelectListItem {Text = "Item 4", Value = "4"},

new SelectListItem {Text = "Item 5", Value = "5"},

new SelectListItem {Text = "Item 6", Value = "6"}

}, "Select Category")


The above code generates a RadioButton list with items 1 to 6., Selected 'true' property shows the specific item as default after the page load.

Comments or Responses

Login to post response