I have a partial view that is being displayed as dialog. I need to do validation in my controller and return the error message in the dialog. How can I do that?
part of my code in the controller is as follows:
if (!String.Equals(newPassword, confirmPassword, StringComparison.Ordinal))
{
ModelState.AddModelError("Confirm Password", "The new password and confirmation password do not match.");
return PartialView("PasswordDetails");
}
the partial view is as follows:
<% using (Html.BeginForm("PasswordDetails", "User"))
{ %>
<td>New password</td><td><%=Html.Password("newPassword")%><input type="hidden" id="ID" name="ID" /></td>
</tr>
<tr>
<td>Confirm new password</td> <td><%=Html.Password("confirmPassword")%><%= Html.ValidationMessage("errors")%>
</td>
</tr>
</table>
<div class="rightalign" >
<input type="submit" value="Accept" /> <input type="button" value="Cancel" id="CloseDialog"/>
</div>
<% } %>