I have the following partial view (I have removed some of the formatting just to keep it simple on this forum). My form tag is on the parent page, and the items on the dialog are a part of that form. This is a strongly typed partial view. I have defined the password and confirmPassword fields as [Required] in my Model.
@Html.LabelFor(m => m.password)
<a href="#" onclick="openResetPasswordDialog();">Reset Password</a>
<div id="dialogResetPassword" title="Reset Password">
<p>Reset password for user: @Model.userId</p>
@Html.LabelFor(m => m.password)
@Html.PasswordFor(m => m.password)
@Html.ValidationMessageFor(m => m.password)
<div class="rowEnd"></div>
@Html.LabelFor(m => m.confirmPassword)
@Html.PasswordFor(m => m.confirmPassword)
@Html.ValidationMessageFor(m => m.confirmPassword)
<div class="rowEnd"></div>
</div>
I have the following javascript for the initialization of the dialog:
function initializeResetPasswordDialog() {
$(resetPasswordDialogId).dialog(
{
autoOpen: false,
autoResize: true,
buttons: {
Ok: function () {
if (!($('#userForm').valid())) {
return false;
}
//more code goes here ...
closeResetPasswordDialog();
},
Cancel: function () {
closeResetPasswordDialog();
}
}
});
}
My dialog initializes, opens and closes fine, but when I try to check the validity of the items in the dialog, I always get "valid".
I do not want to submit the entire form, but just submit the password and the confirm password fields on the Ok button, and also fire up my validations. Any suggestions on how to do this?