控制器文件在應用程序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