我使用的引导模态来创建数据库中一个新的项目。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