我的 RadioButtonFor 绑定到我的后控制器操作时遇到问题。见下文。
主视图- 调用一个动作来加载一个局部视图并用一个表单包围它
@using (Html.BeginForm("FilterPlaceInPriorPosition", "Placements", FormMethod.Post))
{
@Html.Action("AdvancedSearch", "Home", new { Area = "Common", advancedSearchModel = Model.AdvancedSearch })
}
AdvancedSearch 部分控制器操作
public ActionResult AdvancedSearch(AdvancedSearch advancedSearchModel)
{
return PartialView("_AdvancedSearch", advancedSearchModel);
}
部分视图- _AdvancedSearch.cshtml
@model AdvancedSearch
<div class="row">
<div class="col-sm-4">
@Html.TextBoxFor(model => model.Search, new { @class = "form-control no-max-width" })
</div>
<div class="col-sm-8">
@Html.RadioButtonFor(model => model.MyActiveStudents, true, new {Name = "studentTypeRadio"}) <label for="MyActiveStudents">My active students</label>
@Html.RadioButtonFor(model => model.AllActiveStudents, true, new {Name = "studentTypeRadio"}) <label for="AllActiveStudents">All active students</label>
</div>
</div>
发布控制器操作-FilterPlaceInPriorPosition
[HttpPost]
public ActionResult FilterPlaceInPriorPosition(AdvancedSearch filter)
{
return RedirectToAction("PlaceInPriorPosition", filter);
}
AdvancedSearch.cs 类
public class AdvancedSearch
{
public bool MyActiveStudents { get; set; }
public bool AllActiveStudents { get; set; }
如果您查看图像,您会看到文本框文本绑定,但两个单选按钮没有。 调试结果图片