控制器文件在应用程序HomeController.cs中定义了两个控件SetPowerOff和[HttppPost] SetPowerOff。MVC HttpPost接收空参数
public ActionResult SetPowerOff(int ID, string deepness)
{
.............
if (Request.IsAjaxRequest())
{
var viewModel = new HomeSetPowerOffViewModel()
{
//List of devices
Devicelist = list,
age = 18
};
return PartialView("_SetPowerOff", viewModel);
}
else
{
return HttpNotFound();
}
}
[HttpPost]
public ActionResult SetPowerOff(HomeSetPowerOffViewModel homeSetPowerOffViewModel)
{
}
部分视图返回列表中的设备。
@using (Html.BeginForm("SetPowerOff", "Home", FormMethod.Post, new { @class = "form-horizontal" }))
{
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
<h3 id="myModalLabel">Devices information</h3>
</div>
<div class="modal-body ">
<div class="row-fluid">
<div class="span12">
<ul>
@foreach (var devices in Model.Devicelist)
{ <li>
@devices.Name;
</li>
}
</ul>
</div>
</div>
</div>
<div class="modal-footer">
@Html.ActionLink("Cancel", "Index", "Home", new { @class = "btn btn-danger" })
<button type="submit" class="btn btn-success">
Ok
</button>
</div>
}
我按局部视图确定按钮后它去HttpPost请求。这里收到的homeSetPowerOffViewModel为null,年龄为0.我非常想知道为什么要重置它们。 感谢您的时间!
请更新您的视图代码包含数据'age' 。 –
我只需要在部分视图中打印设备的名称。 – Cristian