【发布时间】:2015-02-20 07:56:02
【问题描述】:
我有一个无参数的Index 用于HttpGet,它可以工作。但是当我发布它时,会调用Index 的HttpPost 版本并传入viewmodel 对象,但其中只有下拉列表的值。其余为空(产品、标题)
[HttpPost]
public ActionResult Index(ProductsViewModel pvm)
{
// breakpoint on line 36, shows that pvm.Title is null and Products too.
return View(pvm);
}
我的可编译运行示例可以从我的 OneDrive http://1drv.ms/1zSsMkr下载
我的看法:
@model KleinKloteProductOverzicht.Models.ProductsViewModel
@using (Html.BeginForm("Index", "Products"))
{
<h2>@Html.DisplayFor(m => m.Title)</h2>
<input type="submit" value="post dit" /><br/>
<div class="row">
<div class="col-lg-2 col-md-2">
@Html.DropDownListFor(x => x.CurrentSort, EnumHelper.GetSelectList(typeof(SortOptions)), new { @class = "multiselect"})
</div>
</div>
if (Model.Products.Count() > 0)
{
<div class="row">
@foreach (var item in Model.Products)
{
@Html.DisplayFor(i => item.Name);
}
</div>
}
}
【问题讨论】:
-
你能提供视图相关部分的代码吗?发布时表单数据包含什么?
-
你需要给你看相关的查看代码
-
没有人会费心去下载代码...
-
它必须在您的视图中设置才能被回发。例如,如果您从操作中填写了一个选择列表并将其发送到视图,则在回发时它将为空,因为该属性不是从视图中设置的!
-
大声笑,似乎将测试项目上传到 onedrive 是没用的 ;) 将用我的剃刀视图更新问题
标签: c# model-view-controller asp.net-mvc-5