Showing posts with label MVC 5. Show all posts
Showing posts with label MVC 5. Show all posts

Monday, 30 March 2015

hide input rendered by editorformodel

The problem
We are using following code for login:

@using (Html.BeginForm())
{
    @Html.EditorForModel()
    <p>
        <button type="submit">Log In</button>
    </p>
}

The model is defined as:


 public class LogInModel
    {
        [Required]
        public string Email { get; set; }

        [Required]
        public string Password { get; set; }

        public string ReturnUrl { get; set; }
    }



So every time the page with the model renders, it will create 3 elements for user to imput data

One for email, second for password and the third for return url.

So how do we hide it?

We hide it using data annotation

 [ScaffoldColumn(false)]



so then our model will become:

    public class LogInModel
    {
        [Required]
        public string Email { get; set; }

        [Required]
        public string Password { get; set; }

        [ScaffoldColumn(false)]
        public string ReturnUrl { get; set; }
    }