简体   繁体   English

如何使用jquery隐藏弹出窗口?

[英]How to hide the popup using jquery?

i have two popup, in popup1, if i filled all textboxes and proceed,i will be redirected to popup2. 我有两个弹出窗口,在popup1中,如果我填充所有文本框并继续,我将被重定向到popup2。 otherwise, i should stay in popup1 with the validation message. 否则,我应该留在popup1与验证消息。

Note:If my "caseNum" had valid value i will redirected to popup2 otherwise to popup1. 注意:如果我的“caseNum”具有有效值,我将重定向到popup2,否则重定向到popup1。

i have my code like, 我有我的代码,

function NewCaseForm()//popup1
{
var OwnerAgency = $("#OwnerAgency :selected").val();
var OwnerAgent = $("#OwnerAgent :selected").val();
 var NewCase =
 {
        "OwnerAgency": OwnerAgency,
        "OwnerAgent": OwnerAgent,
       };
$.ajax({
    url: '/Index/NewCase/',
    data: JSON.stringify(NewCase),
    contentType: 'application/json; charset=utf-8',
    type: "POST",
    success: function (caseNum) {
        if (caseNum) {
            var caseNo = caseNum;
            ImportTypeSelectionNewCase(caseNum);//popup2
        }
    },
});

} have my controller like, 让我的控制器像,

   [HttpPost]
    public ActionResult NewCase(NewCase model)
    {
  if (model.MyCaseNumber == null || model.OwnerAgency.ToString() == "" || model.OwnerAgent.ToString() == ""
                || model.AnalystAgency.ToString() == "" || model.AnalystAgent.ToString() == "")
            {
                model.IsValid = true;
                model.ValidationMessage = "Please Enter a New Case Number or Analyst information or Owner information to continue.";
                return View(model);
            }
            else
           {
              int caseId = _ServiceHelper.SaveNewCase(
                    model.OwnerAgency, model.OwnerAgent, );
                string caseNum = model.MyCaseNumber.Replace(" ", "_").Trim()                         + ":" + caseId;
                return Json(caseNum);
                }
           return View("ImportTypeSelection");

But my code does like, instead of showing in popup1 its showing popup2.As iam the beginner i dont know how to resolve this. 但我的代码确实喜欢,而不是在popup1中显示它显示popup2.Asam初学者我不知道如何解决这个问题。 Kindly tell me. 请告诉我。

Unable to comment , so putting as answer... 无法评论,所以作为答案......

  1. Please alert the value of caseNum and check what is returned 请提醒caseNum的值并检查返回的内容

  2. try making you ajax query synchronous async:false; 尝试让你ajax查询同步async:false;

change your controller like this 像这样改变你的控制器

 [HttpPost]
    public ActionResult NewCase(NewCase model)
    {
  if (model.MyCaseNumber == null || model.OwnerAgency.ToString() == "" || model.OwnerAgent.ToString() == ""
                || model.AnalystAgency.ToString() == "" || model.AnalystAgent.ToString() == "")
            {
                return View("");
            }
            else
           {
              int caseId = _ServiceHelper.SaveNewCase(
                    model.OwnerAgency, model.OwnerAgent, );
                string caseNum = model.MyCaseNumber.Replace(" ", "_").Trim()                         + ":" + caseId;
                return Json(caseNum);
                }
           return View("ImportTypeSelection");
}

and your client side function like this 而你的客户端就像这样

        function NewCaseForm()//popup1
        {
        var OwnerAgency = $("#OwnerAgency :selected").val();
        var OwnerAgent = $("#OwnerAgent :selected").val();
         var NewCase =
         {
                "OwnerAgency": OwnerAgency,
                "OwnerAgent": OwnerAgent,
               };
        $.ajax({
            url: '/Index/NewCase/',
            data: JSON.stringify(NewCase),
            contentType: 'application/json; charset=utf-8',
            type: "POST",
            success: function (caseNum) {
                if (caseNum !="") {
                    var caseNo = caseNum;
                    ImportTypeSelectionNewCase(caseNum);//popup2
                }
    else{
     var errorMessageOne="error 1";
 var errorMessageTwo="error 2";
 var errorMessageThree="error 3";
 var errorMessageFour="error 4";

//and use these values 

    }
            }
        });

from now the if only trigger casenum is not an empty string.. and use jsonresult insted of action result if you are in the same page 从现在开始如果只触发casenum不是一个空字符串..并使用jsonresult insted of action result如果你在同一页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM