本文介绍了如何将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

解决方案



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

解决方案



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

10-27 12:34