我有兩個按鈕,下面我的活動形式,處理多個提交按鈕與MVC4剃刀「遠程」驗證
@using (Ajax.BeginForm("Create", "Events", new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = "updateSuccess"
}, new { @id = "updateEventForm" }))
{
<div class="modal-body form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">@Html.LabelFor(model => model.Code)</label>
<div class="col-sm-10">
@if (Model.EventID <= 0)
{
@Html.TextBoxFor(model => model.Code, new { id = "txtCode", Class = "form-control", placeholder = "Code", Value = "E_" + new Random().Next().ToString() })
}
else
{
@Html.TextBoxFor(model => model.Code, new { id = "txtCode", Class = "form-control", placeholder = "Code" })
}
@Html.ValidationMessageFor(model => model.Code)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="Save" class="btn btn-primary" name="action:Save" id="btnSave" />
<input type="submit" value="Save & Next" class="btn btn-primary" name="action:SavenNext" id="btnSaveNext" />
</div>
</div>
</div>
<!-- // Modal body END -->
}
在我的控制器我有以下的「保存」,
而點擊操作[HttpPost]
[MultipleButton(Name = "action", Argument = "Save")]
public ActionResult SaveClick(Events objEvents)
{
int Result = CreateEvent(objEvents);
if (Result == 0)
return null;
else
return RedirectToAction("Index");
}
,並同時對 「保存&下一頁」 點擊,以下操作將被調用,
[HttpPost]
[MultipleButton(Name = "action", Argument = "SavenNext")]
public ActionResult SavenNextClick(Events objEvents)
{
int Result = CreateEvent(objEvents);
if (Result == 0)
return null;
else
return Json(JsonResponseFactory.SuccessResponse(objEvents.SubscriptionID), JsonRequestBehavior.AllowGet);
}
我有如下我的模型遠程驗證,
[Remote("codeExist", "Events", AdditionalFields = "EventID", HttpMethod = "POST", ErrorMessage = "Code must be unique!")]
public string Code { get; set; }
如果我會評論遠程驗證線,然後一切都運行完美,但如果我將繼續驗證,然後按照Create()行爲稱爲(當我需要打開表格),必須被調用,
public ActionResult Create(int SubscriptionID)
{
FillEventTypeDropDown();
objEvents.SubscriptionID = SubscriptionID;
return PartialView(objEvents);
}
,但我需要調用SaveClick ANA SavenNextClick,請任何幫助,進行遠程驗證與多個提交按鈕。
你可以看到你的答案在這裏: [HTTP:/ /stackoverflow.com/questions/442704/how-do-you-handle-multiple-submit-buttons-in-asp-net-mvc-framework][1] [1]:HTTP:// stackoverflow.com/questions/442704/how-do-you-handle-multiple-submit-buttons-in-asp-net-mvc-framework –
@莫斯塔法Soghandi,我已經refrred這個鏈接,我已經根據第一個答案完成我的代碼。但是,仍然沒有完成。 – KomalJariwala