之间的区别:[ScaffoldColumn (false)] 和 [Display (AutoGenerateField = false)]
为了在编辑视图中呈现 HTML,我使用了帮助器 @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()
创建。 (我想手动创建它。)
在网上阅读,我发现了几点,想知道其中的区别。
请记住,我不想隐藏它,该字段只能由此
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 (false)]
和 [Display (AutoGenerateField = false)]
为什么我不能使 [Display (AutoGenerateField = false)] 具有以下效果: '在以下情况下不生成 HTML 字段调用@Html.EditorForModel()`。
To render HTML in my edit view, I use the 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 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; }
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)
Question:
What is the difference between: [ScaffoldColumn (false)]
and [Display (AutoGenerateField = false)]
Why can not I make [Display (AutoGenerateField = false)] have the effect: 'do not generate the HTML field when calling
@Html.EditorForModel()`.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
EditorForModel()
和DisplayForModel()
Html 帮助器方法根据ViewData.ModelMetadata
决定当前模型属性的渲染视图。默认的 DataAnnotationsModelMetadataProvider 根据 DataAnnotation 属性设置 ModelMetadata 的属性。ScaffoldColumnAttribute.Scaffold
影响ModelMetadata
的两个属性,即“ShowForDisplay
”和“ShowForEdit
”。DisplayAttribute
不会影响ModelMetadata
的上述两个属性。这就是为什么这两个属性对生成 Html 没有相同的效果。
The
EditorForModel()
andDisplayForModel()
Html helper methods makes decision of rendering view of the properties of the current Model based on theViewData.ModelMetadata
. The defaultDataAnnotationsModelMetadataProvider
sets the properties of ModelMetadata based on the DataAnnotation attributes.ScaffoldColumnAttribute.Scaffold
affects two properties ofModelMetadata
i.e. 'ShowForDisplay
' and 'ShowForEdit
'.DisplayAttribute
does not affects the above two properties ofModelMetadata
.That is why these two attributes do not have the same effect on generating Html.
我也想知道区别,以下来自MSDN - http://msdn.microsoft.com/en-us/library/dd411771(v=vs.95).aspx
"AutoGenerateField - 指示字段是否为包含在用户界面元素(例如列)的自动生成中。该值由 DataGrid 控件使用。”
由此可见,该特定属性仅适用于 DataGrid。
I also wanted to know the difference, the following is from MSDN - http://msdn.microsoft.com/en-us/library/dd411771(v=vs.95).aspx
"AutoGenerateField - A value that indicates whether the field is included in the automatic generation of user-interface elements such as columns. This value is used by the DataGrid control."
From this it appears that this particular property is meant for DataGrid only.