我使用的引導模態來創建數據庫中一個新的項目。ASP.NET MVC莫代爾BeginForm發送空HtmlAttribute
我有一個包含以下代碼的頁面。頁面網址是.../ProjectManager/Projects/1。
我想通過這個值ID(在URL)到我的模式,然後我需要在表單中使用它。當我運行此代碼時,控制器方法參數id將變爲null。
<a data-toggle="modal" class="btn btn-info" href="AddModule" data-target="#NewModule">New Module</a>
<div class="modal fade" id="NewModule" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title text-left">Add New Module/Submodule</h4>
</div>
@using (Html.BeginForm("AddModule", "ProjectManager", FormMethod.Post, new { id = ViewContext.RouteData.Values["Id"].ToString() }))
{
<div class="modal-body">
<div class="te">
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<div class="col-md-4">
@Html.Label("Module Name", htmlAttributes: new { @class = "control-label col-md-2" })
</div>
<div class="col-md-8">
@Html.Editor("ModuleName", new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<button type="submit" class="btn btn-primary">Create Module</button>
</div>
}
</div>
</div>
</div>
這是我的控制器方法
[HttpPost]
public ActionResult AddModule(string ModuleName, string id)
{
return RedirectToAction("Projects");
}
是的,我已經檢查並沒有id參數發送到該頁面。這是我所要求的。謝謝。 – Halislus 2014-09-29 11:08:16