-->

Sunday, January 19, 2014

About the Folders in MVC Web Application in Visual Studio: Part 2

About the Folders in MVC Web Application in Visual Studio: Part 2

Models folder represents the application model for your MVC application, may be called a template for the views. The classes, defined in this folder, are used to define validations of the respective field. For example username is required and password is of some length.

By default MVC application contains a single model i.e. AccountModel, having all the relative classes usable in account management. These classes may be for login, register, change password etc. A brief look about the login model is:

public class LoginModel
    {
        [Required]
        [Display(Name = "User name")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }

        [Display(Name = "Remember me?")]
        public bool RememberMe { get; set; }
    }

In this class, look out the first field i.e. UserName having some validation i.e. required and display. User have to set some value to username before submit, because it is required and on the view it will be displayed as the string defined.

The second field Password, also a required field and a data type have also been defined for it. The datatype of this field is password means entered string will not be readable. Same as this model, there are register model, change password model are defined with changed fields.

Programmer can write its own models and create their views with respective validation if any. All these models will be placed in the model folder.

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved