I have a jquery dialog that I want to appear when a view doesn't contain an expected answer. Th开发者_运维问答e problem is the code execution continues to the controller action before a response is accepted by the dialog.
Here is the javascript code for the submit button.
$('#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');
);
The submit button is within a form in this view code.
<% 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>
--%>
<% } %>
I have spent alot of time on this any help would be appreciated.
Thanks Traci
From the code posted above, looks like you are handling the submit (calling CallSubmit) once the user selects OK/Yes, hence return false at the end of the event handler.
Change:
$('#Submit1').click(function () {
.
.
.
.
//You existing code.
});
to
$('#Submit1').click(function () {
.
.
.
.
//You existing code.
return false;
});
精彩评论