Search results

Name and Value in form submit in ASP.NET MVC RadioButton control

03 Mar 2021 / 1 minute to read

The name attribute of the RadioButton is used to group RadioButton. When the RadioButton are grouped in form, the checked items value attribute will be post to server on form submit that can be retrieved through the name. The disabled RadioButton value will not be sent to the server on form submit.

In the following code snippet, Credit and Debit card is in checked state. Now, the value that is in checked state will be sent on form submit.

razor
form.cs
Copied to clipboard
@Html.EJS().RadioButton("radio1").Label("Credit/Debit Card").Name("payment").Checked(true).Render()
@Html.EJS().RadioButton("radio2").Label("Net Banking").Name("payment").Render()
@Html.EJS().RadioButton("radio3").Label("Cash on Delivery").Name("payment").Render()
@Html.EJS().RadioButton("radio4").Label("Others").Name("payment").Render()
@Html.EJS().Button("primarybtn").Content("Submit").IsPrimary(true).Render()

<style>

.e-radio-wrapper {
  margin-top: 18px;
}

button {
  margin: 20px 0 0 5px;
}

li {
  list-style: none;
}

</style>
Copied to clipboard
public ActionResult Form()
{
    return View();
}