问题描述
我的活动表单中有两个按钮,如下所示,
I have two buttons in my Event form as below,
@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 -->
}
在我的控制器"中,单击"保存"后,我将执行以下操作,
In My Controller I have following action while click on "Save",
[HttpPost]
[MultipleButton(Name = "action", Argument = "Save")]
public ActionResult SaveClick(Events objEvents)
{
int Result = CreateEvent(objEvents);
if (Result == 0)
return null;
else
return RedirectToAction("Index");
}
,然后单击"保存并下一步",将执行以下操作,
and while click on "Save & Next", following action will be called,
[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);
}
我对我的模型进行了远程验证,如下所示,
I have Remote validation on my model as below,
[Remote("codeExist", "Events", AdditionalFields = "EventID", HttpMethod = "POST", ErrorMessage = "Code must be unique!")]
public string Code { get; set; }
如果我要注释远程验证行,则一切正常,但如果我保持验证状态,则将调用以下Create()动作(当我需要打开表单时必须调用它)
If i will comment Remote validation line, then everything works perfect but if i will remain validation, then following Create() action is called(which must be called when i need to open form),
public ActionResult Create(int SubscriptionID)
{
FillEventTypeDropDown();
objEvents.SubscriptionID = SubscriptionID;
return PartialView(objEvents);
}
但是我需要致电SaveClick或SavenNextClick,请使用多个提交按钮的远程验证提供任何帮助.
But i need to call SaveClick ana SavenNextClick, Please any help for remote validation with multiple submit button.
推荐答案
<input type="submit" value="Save" class="btn btn-primary" name="actionname" id="btnSave" />
<input type="submit" value="Save & Next" class="btn btn-primary" name="actionname" id="btnSaveNext" />
和控制器端仍然与先前的答案相同.actionname参数将从按钮中获取值:因此在这种情况下,请执行Save或Save&下一个
and controller side still remain the same as in previous answer.actionname parameter is going to take the values from the button: so in this case Save or Save & Next
对不起,我以前的回答是错误的
Sorry my mistake on previous answer
这篇关于使用& quot; Remote& quot;处理多个提交按钮在MVC4剃须刀中进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!