如何将Ajax.BeginForm中的Onsuccess通知为false。 [英] How to notify Onsuccess in Ajax.BeginForm as false.

查看:88
本文介绍了如何将Ajax.BeginForm中的Onsuccess通知为false。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public  PartialViewResult AddBranchContact(BranchViewModel objBranchContact)
{
List< BranchContact> BranchContactList = new List< BranchContact>();
if (ModelState.IsValid)
{
if (Session) [ BranchContactList] == null
{
objBranchContact.BranchContactDetails.BranchContactID = 1 ;
BranchContactList.Add(objBranchContact.BranchContactDetails);
会话[ BranchContactList] = BranchContactList;
return PartialView( PartialViewAddBranchContact,BranchContactList);
}
else
{
List< BranchContact> ContactList =会话[ BranchContactList] as 列表< BranchContact> ;;
ContactList.Add(objBranchContact.BranchContactDetails);
会话[ BranchContactList] = ContactList;
return PartialView( PartialViewAddBranchContact,ContactList);
}
}
else
{
return PartialView( PartialViewAddBranchContact);
}



查看:

 @ using(Ajax.BeginForm(AddBranchContact,new AjaxOptions {HttpMethod =POST,OnSuccess =$('#myModal1')。modal('hide');,UpdateTargetId =myTable}))
{}



这里OnSuccess我隐藏了一个模态弹出窗口。但我现在有一个场景,其中有一些字段必须填写弹出窗口。

如果不是调试器没有进入ModelState.IsValid那么基本上OnSuccess应该变为false。



如何通知这个?

我想要的是如果不满足Modelstate.isvalid它不应该隐藏modalpopup

解决方案

('#myModal1')。modal( 'hide');,UpdateTargetId =myTable}))
{}



这里OnSuccess我隐藏了一个模态弹出窗口。但我现在有一个场景中有一些字段必须填写弹出窗口。

如果不是调试器没有进入ModelState.IsValid所以基本上OnSuccess应该变为false。



如何通知这个?

我想要的是如果Modelstate.isvalid不满意则不应该隐藏modalpopup


你需要在 AjaxOptions 中为 OnBegin (字符串)定义js以验证表单,如果必填字段则返回false未填写。您可以使用jQuery验证是否填写了必填字段,或使用 jQuery Validate [ ^ ]插件为您进行验证!有很多关于OnBegin的教程/链接让你熟悉w / it !!



直接退出谷歌没有特别的顺序!:



jquery - 如何在Ajax.Begin表单中使用onBegin验证请求? - 堆栈溢出 [ ^ ]

如何使用Ajax.BeginForm | onBegin方法Yasser Shaikh [ ^ ]

public PartialViewResult AddBranchContact(BranchViewModel objBranchContact)
{
    List<BranchContact> BranchContactList = new List<BranchContact>();
    if (ModelState.IsValid)
    {
       if (Session["BranchContactList"] == null)
       {
           objBranchContact.BranchContactDetails.BranchContactID = 1;
           BranchContactList.Add(objBranchContact.BranchContactDetails);
           Session["BranchContactList"] = BranchContactList;
    return PartialView("PartialViewAddBranchContact", BranchContactList);
       }
       else
       {
    List<BranchContact> ContactList = Session["BranchContactList"] as List<BranchContact>;
           ContactList.Add(objBranchContact.BranchContactDetails);
           Session["BranchContactList"] = ContactList;
    return PartialView("PartialViewAddBranchContact", ContactList);
       }
    }
    else
    {
       return PartialView("PartialViewAddBranchContact");
    }


View :

@using (Ajax.BeginForm("AddBranchContact", new AjaxOptions { HttpMethod = "POST", OnSuccess = "$('#myModal1').modal('hide');", UpdateTargetId = "myTable" }))
{}


Here OnSuccess i am hiding a modal popup. But i now have a scenario where in there are some fields which are mandatory to be filled in the popup.
If not the debugger doesnt go into ModelState.IsValid so basically OnSuccess should become false.

How do i notify this?
What i want is if Modelstate.isvalid is not satisfied it shouldnt hide the modalpopup

解决方案

('#myModal1').modal('hide');", UpdateTargetId = "myTable" })) {}


Here OnSuccess i am hiding a modal popup. But i now have a scenario where in there are some fields which are mandatory to be filled in the popup.
If not the debugger doesnt go into ModelState.IsValid so basically OnSuccess should become false.

How do i notify this?
What i want is if Modelstate.isvalid is not satisfied it shouldnt hide the modalpopup


You need to define the js for OnBegin (string) available in AjaxOptions to validate the form and return false if the mandatory fields are not filled in. You can either use jQuery to verify if the mandatory fields are filled in or use the jQuery Validate[^] plugin to do the validation for you! There are numerous tutorials / links about OnBegin for you get familiar w/ it!!

Straight out of google in no particular order!:

jquery - how to validate the request using onBegin in Ajax.Begin Form? - Stack Overflow[^]
How to use onBegin method with Ajax.BeginForm | Yasser Shaikh[^]


这篇关于如何将Ajax.BeginForm中的Onsuccess通知为false。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆