【发布时间】:2018-07-18 21:04:21
【问题描述】:
我有一个表单可以在如下视图中创建一个对象:
@using (Html.BeginForm("Create", "Request", FormMethod.Post, new { id = "createForm" }))
{
@Html.HiddenFor(model => model.RequestDate)
@Html.HiddenFor(model => model.Requester)
<div class="form-horizontal col-md-5">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<div class="mui-select">
@Html.DropDownListFor(model => model.CategoryId, new SelectList(ViewBag.Categories, "Key", "Value"))
<label>Category</label>
</div>
@Html.ValidationMessageFor(model => model.CategoryId, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<div class="mui-textfield mui-textfield--float-label">
@Html.TextBoxFor(model => model.Requester, new { disable = "disabled", @readonly = "readonly" })
<label>Requester</label>
</div>
</div>
<div class="form-group">
<div class="mui-textfield mui-textfield--float-label">
@Html.TextBoxFor(model => model.RequestDate, new { @id = "txtRequestDate" })
<label>Request Date</label>
</div>
</div>
<div class="form-group">
<div class="mui-select">
@Html.DropDownListFor(model => model.ParentRequestId, new SelectList(ViewBag.Requests, "Key", "Value"))
<label>Parent Request</label>
</div>
@Html.ValidationMessageFor(model => model.ParentRequestId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-horizontal col-md-5" style="float:right;">
<div class="form-group">
<div class="mui-select">
@Html.EnumDropDownListFor(model => model.Destination, "Select Destination Site...", new { type = "text" })
<label>Destination Site</label>
</div>
</div>
<div class="form-group">
<div class="mui-textfield mui-textfield--float-label">
@Html.TextBoxFor(model => model.ETDDate, new { @id = "txtETDDate" })
<label>ETD Date</label>
</div>
</div>
<div class="form-group">
<div class="mui-select">
@Html.EnumDropDownListFor(model => model.ReasonCode, "Select Reason...", new { type = "text" })
<label>Reason Code</label>
</div>
</div>
<div class="form-group">
<div class="mui-textfield mui-textfield--float-label">
@Html.EditorFor(model => model.Reason, null)
<label>Reason</label>
</div>
</div>
</div>
}
如您所见,这应该以 POST 请求的形式点击 /Request/Create。
我在表单之外有一个按钮:
<li id="new-menu" class="top-level">
<a href="#" id="saveBtn">Save</a>
</li>
这通过 jquery 提交:
$('#saveBtn').on('click', function () {
$('#createForm').submit();
});
我在RequestController 中的控制器方法是:
[HttpPost]
public async Task<ActionResult> Create(Request request)
{
//DO STUFF
return RedirectToAction("Detail", new { id = request.Id });
}
但是在此方法的第一行设置断点,并没有给我任何东西,因为它没有触发动作。
我已经在开发者工具的网络选项卡中检查了调用,并且请求的主体很好,它已经正确获取了所有细节,因此它与操作所期望的Request 对象相匹配。它还返回一个200 响应代码,但响应本身没有任何内容。
我不确定如何进一步调试并找到实际问题。
有人有什么建议吗?
在此先感谢 :)
** 编辑 **
为了澄清,我对此的回应是浏览器中的一个空白页面,但显然我知道它没有使用断点访问控制器。
【问题讨论】:
标签: jquery asp.net-mvc forms