区别:[ScaffoldColumn(假)]和[显示器(AutoGenerateField = FALSE)] [英] difference between: [ScaffoldColumn (false)] and [Display (AutoGenerateField = false)]
问题描述
要呈现的HTML编辑我的看法,我使用助手 @ Html.EditorForModel()
。
To render HTML in my edit view, I use the helper @Html.EditorForModel()
.
我的模型:
[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 e a 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; }
属性: codeGuest
不应该由助手创建的 @ Html.EditorForModel()
。 (我想手动创建它。)
Property: CodeGuest
should not be created by the helper @Html.EditorForModel()
. (I would like to create it manually.)
在互联网上阅读,我发现了几个点,想知道其中的差别。
Reading on the Internet, I found several points and would like to know the difference.
记住,我不希望它被隐藏呢,这个领域将只通过该创建
Remembering that I do not want it 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)
问:
之间有什么区别: [ScaffoldColumn(假)]
和 [显示(AutoGenerateField = FALSE)]
为什么我不能让 [显示(AutoGenerateField = FALSE)有效果:打电话时不生成HTML字段
@ Html.EditorForModel()`。
Why can not I make [Display (AutoGenerateField = false)] have the effect: 'do not generate the HTML field when calling
@Html.EditorForModel()`.
推荐答案
的 EditorForModel()
和 DisplayForModel()
HTML辅助方法,使渲染鉴于目前的模型基础上, ViewData.ModelMetadata code>属性决定。默认
DataAnnotationsModelMetadataProvider
设置ModelMetadata的基础上,DataAnnotation属性属性。
The EditorForModel()
and DisplayForModel()
Html helper methods makes decision of rendering view of the properties of the current Model based on the ViewData.ModelMetadata
. The default DataAnnotationsModelMetadataProvider
sets the properties of ModelMetadata based on the DataAnnotation attributes.
ScaffoldColumnAttribute.Scaffold
影响 ModelMetadata code>的两个属性,即
ShowForDisplay
和 ShowForEdit
。
ScaffoldColumnAttribute.Scaffold
affects two properties of ModelMetadata
i.e. 'ShowForDisplay
' and 'ShowForEdit
'.
DisplayAttribute
不影响到 ModelMetadata code>上面的两个属性。
DisplayAttribute
does not affects the above two properties of ModelMetadata
.
这就是为什么这些两个属性不会对产生的Html同样的效果。
That is why these two attributes do not have the same effect on generating Html.
这篇关于区别:[ScaffoldColumn(假)]和[显示器(AutoGenerateField = FALSE)]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!