2011-07-13 3 views
0

ビューに期待される回答が含まれていない場合に表示するjqueryダイアログがあります。 問題は、応答がダイアログによって受け入れられる前に、コントローラのアクションにコードが実行されることです。MVCアプリケーションのJqueryダイアログまたはjqdialogは、レスポンスの前にcontollerアクションまで続きます。

ここには送信ボタンの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> 
--%> 

<%}%>

。ユーザーがOKを選択したら(CallSubmitを呼び出す)を提出処理しているように上記掲載のコードから感謝トレイシー

答えて

0

は、見え/はい、それ故にイベントハンドラの最後にfalseを返します。

変更:

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

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

}); 

関連する問題