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

时间:2015-03-06 06:24:09

标签: jquery razor model-view-controller

我有两个弹出窗口,在popup1中,如果我填充所有文本框并继续,我将被重定向到popup2。否则,我应该使用验证消息留在popup1中。

注意:如果我的" caseNum"有效值我会重定向到popup2否则弹出1。

我有我的代码,

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
        }
    },
});

}   让我的控制器像,

   [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");

但我的代码确实喜欢,而不是在popup1中显示它显示popup2.Asam初学者我不知道如何解决这个问题。请告诉我。

2 个答案:

答案 0 :(得分:0)

无法发表评论,所以作为答案......

  1. 请提醒caseNum的值并检查返回的内容

  2. 尝试让你ajax查询同步async:false;

答案 1 :(得分:0)

像这样改变你的控制器

 [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");
}

并且您的客户端功能如下

        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 

    }
            }
        });

从现在开始如果只触发casenum不是一个空字符串..如果你在同一页面,则使用jsonresult insted action action