【发布时间】:2015-12-09 15:22:00
【问题描述】:
我的 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; }
如果您查看图像,您会看到文本框文本已绑定,但两个单选按钮没有。 debugging results image
【问题讨论】:
标签: c# asp.net-mvc razor partial-views radiobuttonfor