我的MVC应用程序中有几个单选按钮,我已经应用了css样式来显示图像而不是实际的单选按钮圆圈。我坚持找到一种方法将选定的单选按钮值传递给控制器。我曾尝试在线寻找解决方案,但无法找到任何解决方案。任何帮助将不胜感激。
@model xxxx.xxxxx.xxxx.AddEmployeeCommand
@using (Html.BeginForm("Index", "EmployeeDetails", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<label class="label"> Name </label> @Html.TextBoxFor(model => model.Name)
<input type="radio" class="radio_item" value="Male" name="item" id="Male">
<label class="label_item" for="Male">
<img src="~/Images/Test1.png" width="40" height="40" />
</label>
<input type="radio" class="radio_item" value="Female" name="item" id="Female">
<label class="label_item" for="Female">
<img src="~/Images/Test2.png" width="40" height="40" />
</label>
}
这是我的CSS
.radio_item {
display: none !important;
}
.label_item {
opacity: 0.5;
}
.radio_item:checked + label {
opacity: 1;
}
这是我的控制器类,
public class EmployeeDetailsController : Controller
{
[HttpPost]
public ActionResult Index(AddEmployeeCommand command)
{
employeeCommandHandler.Save(command);
return View();
}
}
答案 0 :(得分:0)
您必须绑定组中的所有无线电选项,即。到同一财产。然后,您可以将其发布到控制器/操作..
请参阅以下链接,它将有所帮助.. When using .net MVC RadioButtonFor(), how do you group so only one selection can be made?