2011-07-13 18 views
0

我有一个jQuery对话框,当视图不包含预期的答案时,我想要显示该对话框。 问题是在响应被对话框接受之前,代码执行继续执行控制器操作。jQuery对话框或MVC应用程序中的jqdialog在响应之前继续到控制器操作

这里是提交按钮的JavaScript代码。

$('#Submit1').click(function() { 
     var yes = $("#yes"); 
     var no = $("#no"); 
     var errorInd = $("#errorMsg"); 

     if ((yes[0] == undefined || yes[0] == null) && no[0] == undefined || no[0] == null) { 
      var answer = $("#answer"); 
      var answer2 = $("#answer2"); 
      if (answer[0] != undefined && answer2[0] != undefined) { 
       if (answer[0].value == "" && answer2[0].value == "") { 
        errorInd[0].style.display = ''; 
        $("#errorMsg").css({ visibility: 'visible' }); 
       } 
      } 
     } else if (!yes[0].checked && !no[0].checked) { 
      // alert dialog 
     $.jqDialog.confirm("Are you sure want to continue?", 
         function() { CallSubmit();  }, // callback function for 'YES' button 
         function() { alert("This intrusive alert says you clicked NO"); } // callback function for 'NO' button   ); 
     // $('#errorMessage').dialog('open'); 


     ); 

提交按钮在此视图代码中的表单中。

<% using (Html.BeginForm("UpdateAnswer", "Home", FormMethod.Post)) { %> 
    <% foreach (var question in Model) { %> 

    <% if (question.AnswerType== 1) { %> 

    <% Html.RenderPartial("YesNo", question);} %> 
    <% else if (question.AnswerType == 0) { Html.RenderPartial("TextView", question);} %> 
    <% else if (question.AnswerType == 2) { Html.RenderPartial("TwoTextView", question); } %> 
    <% else if (question.AnswerType == 3) { Html.RenderPartial("TextOnlyView", question); } %> 
    <% else if (question.AnswerType == 5) { Html.RenderPartial("RadioListView", question); } %> 

    <% else if (question.AnswerType == 7) { Html.RenderPartial("SingleDateTimeView", question); } %> 

    <% else if (question.AnswerType == 6) { Html.RenderPartial("DateRangeView", question); } %> 
     <input type="hidden" name="qNumber" value='<%: question.QuestionID %>' /> 
     <input type="hidden" name="answerType" value='<%: question.AnswerType%>' /> 


     <% } %> 

    <div id="errorMsg" class="errorMsg" style="display:none">* select yes or no</div> 
    <input type="hidden" name="groupCount" value='<%: Model.Count %>' /> 
    <input type="submit" value="Next" id="Submit1" name="submit" /> 
<%-- <li><%: Html.ActionLink("Error Message Dialog", "ErrorInAnswer", "Home", new { @class = "modalDlg", title = "Error Message" })%></li> 
--%> 

<%}%>

我花了很多时间在这个任何帮助,将不胜感激。

感谢崔西

回答

0

从上面发布的代码,看起来像你正在处理的提交(调用CallSubmit),一旦用户选择OK /是的,因此在事件处理结束返回false。

变化:

$('#Submit1').click(function() { 
. 
. 
. 
. 
//You existing code. 

}); 

$('#Submit1').click(function() { 
. 
. 
. 
. 
//You existing code. 
return false; 
}); 
相关问题