The difference between: [ScaffoldColumn (false)] and [Display (AutoGenerateField = false)]

To display HTML in my edit view, I use helper @Html.EditorForModel() .

My model:

 [Required(ErrorMessage = "Campo obrigatório")] [Display(Name = "Nome completo")] public string Name { get; set; } [Required(ErrorMessage = "Campo é obrigatório")] [StringLength(100, ErrorMessage = "A {0} deve ter pelo menos {2} characteres.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Senha")] public string Password { get; set; } [DataType(DataType.Password)] [Display(Name = "Confirmar senha")] [Compare("Password", ErrorMessage = "A nova senha ea confirmação da senha não conincidem.")] public string ConfirmPassword { get; set; } [Required(ErrorMessage = "Campo obrigatório")] [Display(Name = "Convidado")] [UIHint("IsGuest")] public bool IsGuest { get; set; } [RequiredIf("IsGuest", true, ErrorMessage = "Campo é obrigatório")] [ScaffoldColumn(false)] public string CodeGuest { get; set; } 

Property: CodeGuest should not be created by the @Html.EditorForModel() . (I would like to create it manually.)

Reading on the Internet, I found a few points and would like to know the difference.

Remembering that I do not want this to be hidden, this field will only be created by this

EditorTemplates (IsGuest.cshtml):

 @using BindSolution.AndMarried.Model; @model BindSolution.AndMarried.Models.RegisterModel @Html.EditorFor(e => e.IsGuest) <span>TESTE</span> @Html.EditorFor(e => e.CodeGuest) 

Question:

What is the difference between: [ScaffoldColumn (false)] and [Display (AutoGenerateField = false)]

Why can't I do [Display (AutoGenerateField = false)] have the effect: 'do not generate the HTML field when calling @ Html.EditorForModel () `.

+6
source share
2 answers

The EditorForModel() and DisplayForModel() methods of the Html helper decide to present the properties of the current model based on ViewData.ModelMetadata . By default, DataAnnotationsModelMetadataProvider sets DataAnnotationsModelMetadataProvider properties based on DataAnnotation attributes.

ScaffoldColumnAttribute.Scaffold affects two properties of ModelMetadata ie ' ShowForDisplay ' and ' ShowForEdit '.

DisplayAttribute does not affect the following two properties of ModelMetadata .

This is why these two attributes do not have the same effect when generating Html.

+2
source

I also wanted to know the difference, from MSDN - the following: http://msdn.microsoft.com/en-us/library/dd411771(v=vs.95).aspx

"AutoGenerateField is a value indicating whether the field is included in the automatic generation of user interface elements such as columns. This value is used by the DataGrid control."

It can be seen from this that this particular property is for DataGrid only.

+2
source

Source: https://habr.com/ru/post/897865/


All Articles