Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC validation for column that's not in database
    primarykey
    data
    text
    <p>So I have following table in my database:</p> <pre><code>Account [Id (PK, int), Name(string), Password(string)] </code></pre> <p>I use an ADO.NET Entity Data Model (.edmx) and an ADO.NET Self-Tracking Entity Generator to automaticly generate my models.</p> <p>I want to create an Account/Create page for users to create a new account on my website. Obviously, I want to have both a password field and a confirmPassword field to validate the user input. I have following validation model to pull this off:</p> <pre><code>namespace MD5DatabaseTest.Models { [MetadataType(typeof(AccountMetaData))] public partial class Account {} public class AccountMetaData { public int Id { get; set; } [Required(ErrorMessage = "Please type a username")] public String Name{ get; set; } [Required(ErrorMessage = "Please type a password")] public String Password { get; set; } [Required(ErrorMessage = "Please confirm your password")] [Compare("Password", ErrorMessage = "Passwords do not match")] public String ConfirmPassword{ get; set; } } } </code></pre> <p>Since my Database doesn't have a ConfirmPassword column my Create.cshtml code obviously fails here:</p> <pre><code>&lt;div class="editor-label"&gt; Confirm your password &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.Password("ConfirmPassword") @Html.ValidationMessageFor(model =&gt; model.ConfirmPassword) &lt;/div&gt; </code></pre> <p>It is possible to validate this using the MVC 3 Data Annotions? Or do I have to write a seperate Jscript function for (client-side) validation?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload