我不知道我做错了什么。好吧,我有这个表格,它是复杂视图的一部分。
@{
var filtersAjaxOptions = new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "clientList-body",
OnBegin = "clientList.filterRequestStart()",
OnComplete = "clientList.filterRequestComplete()",
OnSuccess = "clientList.filterRequestSuccess()"
};
}
<span class="clientFilters-filterValue inlineBlock">
@using (Ajax.BeginForm(
"Index",
"ClientList",
new {
ProductId = Model.ClientListViewModel.Filters.ProductId,
ClientFilter = Model.ClientListViewModel.Filters.ClientFilter,
BillFilter = Model.ClientListViewModel.Filters.BillFilter,
DateSortType = Model.ClientListViewModel.Filters.DateSortType,
SortDirection = Model.ClientListViewModel.Filters.SortDirection
},
filtersAjaxOptions,
new
{
id = "clientListDateFilter-form"
}
))
{
@Html.TextBoxFor(
m => m.ClientListViewModel.Filters.BeginDateRange,
new
{
@class = "dp-input textInput inlineBlock",
id = "dp-billDateFilterStart",
}
)
@Html.TextBoxFor(
m => m.ClientListViewModel.Filters.EndDateRange,
new
{
@class = "dp-input textInput inlineBlock",
id = "dp-billDateFilterEnd",
}
)
}
</span>
这是过滤器模型
public class FilterModel
{
public FilterModel()
{
ClientFilter = ClientsEnum.All;
BillFilter = ClientBillsEnum.All;
}
public string ProductId { get; set; }
public ClientsEnum ClientFilter { get; set; }
public ClientBillsEnum BillFilter { get; set; }
public DateTime? BeginDateRange { get; set; }
public DateTime? EndDateRange { get; set; }
public DateSortType? DateSortType { get; set; }
public SortDirection? SortDirection { get; set; }
}
这部分是ClientListController方法索引:
public ActionResult Index(FilterModel filters)
{
var clientListViewModel = GetClientListViewModel(filters, 1, 1, PageSize);
if (ControllerContext.HttpContext.Request.IsAjaxRequest())
return PartialView("Partial/ClientListBody", clientListViewModel);
return View(clientListViewModel);
}
每当我提交上面的表格时,我发现“BeginDateRange”和“EndDateRange”字段为空,其他字段设置正确。虽然,当我在 Watch 中插入Request.Form时,我可以看到整个数据。
更新 1 所以我将 Web.config 中的 <globalisation> 设置为:
<globalisation responseHeaderEncoding="utf-8" culture="en-US">
但它不起作用。结果和之前非常相似。
更新 2 此外,当我尝试将所有路由值数据放入 @Html.HiddenFor 时,控制器只看到空值。再一次,Request.Form 已填写完毕。
所以问题是:如何将表单数据绑定到传入模型?泰