現在、MVC 5アプリケーションのレコード機能を挿入しようとしています。なんらかの理由で、ポストアクションメソッドは起動しません。私はポストアクションメソッドをトリガする必要があるビュー上のボタンを作成しました。なぜそれが発射されていないのか分かりません。フォーム要素は部分的なビューにあり、ボタンコントロールは部分ビューをホストするメインビューではありません。ここでMVCポストアクションメソッドが起動しない
はコード
メインビューは
@model CC.GRP.MCRequest.ViewModels.NewRequestViewModel
<div class="newrequest">
@Html.Partial("~/Views/Request/RequestHeaderView.cshtml");
</div>
<div id="buttonalign" class="buttonalign" >
<button type="button" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-default" onclick="location.href='@Url.Action("Request_Insert", "Request")'" >Save as draft</button>
</div>
要求ヘッダーを表示
@model CC.GRP.MCRequest.ViewModels.NewRequestViewModel
@using (Html.BeginForm())
{
<div id="NewRequest">
<div class="row">
<div class="col-md-4">
<div class="form-group">
@Html.LabelFor(model => model.RequestID, htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-6">
<div class="editor-field">
@Html.EditorFor(model => model.RequestID, new { htmlAttributes = new { @class = "form-control", style = "width:100%", @readonly = "readonly" } })
</div>
@Html.ValidationMessageFor(model => model.RequestID, "", new { @class = "text-danger" })
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
@Html.LabelFor(model => model.Name1, htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-6">
<div class="editor-field">
@(Html.Kendo().ComboBoxFor(model => model.Name1)
.HtmlAttributes(new { style = "width:100%" })
.DataTextField("Name1")
.DataValueField("CustomerMasterDataId")
.DataSource(dataSource => dataSource
.Read(read => read.Action("RequestHeader_CustomerData", "Request").Type(HttpVerbs.Post))
)
.Events(e =>
{
e.Change("onCustomerComboChange");
})
)
</div>
@Html.ValidationMessageFor(model => model.CustomerNumber, "", new { @class = "text-danger" })
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
@Html.LabelFor(model => model.CustomerNumber, htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-6">
<div class="editor-field">
@Html.EditorFor(model => model.CustomerNumber, new { htmlAttributes = new { @class = "form-control", style = "width:100%", @readonly = "readonly" } })
</div>
@Html.ValidationMessageFor(model => model.CustomerNumber, "", new { @class = "text-danger" })
</div>
</div>
</div>
</div>
リクエストコントローラ
です[HttpPost]
public ActionResult Request_Insert(NewRequestViewModel userVM)
{
NewRequestViewModel newReqeustViewModel = new NewRequestViewModel();
if (!ModelState.IsValid)
{
return null;
}
requestRepository.CreateRequest(Mapper.Map<Request>(userVM));
//return Json(requestRepository.CreateRequest(userVM));
return View("NewRequestView", newReqeustViewModel);
}
にあなたは送信ボタンを持っていない、とあなたが持っている_do_ボタンがフォームの一部ではありません。フォームの仕組みを知っていますか? –
ボタンをsubmitに変更しました。また、フォーム要素のメインビューの内容を囲みます。それでもまだ仕事が分かりません – Tom
あなたが今行った変更を反映するようにあなたのコードを更新できますか? Tieson T.が言ったように、送信ボタンがあなたのフォームに同封されていないと言う理由で、現在ここにあるものは間違いなく動作しません。 – sovemp