ReadOnly attribute doesn't work in ASP.NET MVC Models

后端 未结 4 1982
逝去的感伤
逝去的感伤 2020-12-18 20:41

I have marked a property as readonly in the model class, like this:

public class RegisterModel
{
    [Display(Name = \"User name\")]
    [Re         


        
4条回答
  •  时光说笑
    2020-12-18 20:48

    ReadOnly attribute doesn't block the HMTL helper to display the field as an enabled input. It is an information that the only the MVC data Binder will respect.

    It means that RegisterModel instance, which will be posted back after form submission by a user, will always has null value on it's UserName property, regardless of user's input in the appropriate field of the form.

提交回复
热议问题