I have three radio button but when i select EFG and post it to controller I always get ABC in Selected property.
View
@Html.RadioButtonFor(m => m.Selected, AllEnum.ABC) <label>ABC</label>
@Html.RadioButtonFor(m => m.Selected, AllEnum.EFG)<label>EFG</label>
@Html.RadioButtonFor(m => m.Selected, AllEnum.QWE)<label>QWE</label>
Model
public AllEnum Selected{ get; set; }
can you help me out in getting selected radiobutton value in controller.
Below is the working code.
Model
public enum AllEnum
{
ABC,
EFG,
QWE
}
public class SimpleModel
{
public AllEnum Selected { get; set; }
}
Controller
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
var model = new SimpleModel();
return View(model);
}
[HttpPost]
public ActionResult Index(SimpleModel model)
{
return View(model);
}
}
View
@using SimpleMVC.Models
@model SimpleMVC.Models.SimpleModel
@using (Html.BeginForm())
{
@Html.RadioButtonFor(m => m.Selected, AllEnum.ABC) <label>ABC</label>
@Html.RadioButtonFor(m => m.Selected, AllEnum.EFG)<label>EFG</label>
@Html.RadioButtonFor(m => m.Selected, AllEnum.QWE)<label>QWE</label>
<input type="submit" />
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.