c# - ASP.NET MVC: How do I validate a model wrapped in a ViewModel? -


For the login page of my website, I would like to list the latest news for my site and to display some areas Also show the user log in. So I thought I should create a login view - I call it LoginVM .

LoginVM in the Login model for the model and the news list is a list & lt; NewsItem & gt; .

This is login model:

  public class login {[required (error message) "Enter username".]] [DisplayName ("User name")] public string username {get; Set; } [Required (error message = "Enter a password."]] [Datatype (datatype password)] [DisplayName ("password")] public string password {get; Set; }}  

This is LoginVM visual model:

  public class LoginVM {public login login {get; Set; } Public listing & lt; NewsItem & gt; News set; }}  

This is where I get trapped. In my login controller, I was passed LoginVM .

  [HTTP post] Public Function entry (loginVM model, form collection form) {if (ModelState.IsValid) {/?   

In the code I see that ModelState is valid and it will work fine if the visual model is actually a login model, but Now it is LoginVM , which has no verification attributes.

How do I LoginVM "traverse" to verify all my members? Am I doing something wrong by using the ModelState in this way?

see this:

  public class loginVM {[required] public Login login {get; Set; } Public listing & lt; NewsItem & gt; News set; }}  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -