Put it like this:
@Html.RadioButton("teste", "teste", true)
@Html.RadioButton("teste", "concessionaria")
Because the input
type
radio
must bear the same name, the difference being value
.
Example with form:
<form action="/Estudo/Post" method="post" enctype="multipart/form-data">
@Html.RadioButton("teste", "teste", true)
@Html.RadioButton("teste", "concessionaria")
<button>Enviar</button>
</form>
Rendered Html:
<form action="/Estudo/Post" method="post" enctype="multipart/form-data">
<input checked="checked" id="teste" name="teste" type="radio" value="teste" />
<input id="teste" name="teste" type="radio" value="concessionaria" />
<button>Enviar</button>
</form>
Note that the two have the same name with different value that can be recovered by the method Post
.
Recovering by the Method Post
public ActionResult Post(string teste)
{
return View();
}
Debug:
You can use attr('checked', true) true or false in case.
– f.fujihara