之间的区别:[ScaffoldColumn (false)] 和 [Display (AutoGenerateField = false)]

发布于 2024-12-05 18:50:38 字数 1621 浏览 3 评论 0原文

为了在编辑视图中呈现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤城病女 2024-12-12 18:50:38

EditorForModel()DisplayForModel() Html 帮助器方法根据 ViewData.ModelMetadata 决定当前模型属性的渲染视图。默认的 DataAnnotationsModelMetadataProvider 根据 DataAnnotation 属性设置 ModelMetadata 的属性。

ScaffoldColumnAttribute.Scaffold 影响 ModelMetadata 的两个属性,即“ShowForDisplay”和“ShowForEdit”。

DisplayAttribute 不会影响 ModelMetadata 的上述两个属性。

这就是为什么这两个属性对生成 Html 没有相同的效果。

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 affects two properties of ModelMetadata i.e. 'ShowForDisplay' and 'ShowForEdit'.

DisplayAttribute does not affects the above two properties of ModelMetadata.

That is why these two attributes do not have the same effect on generating Html.

静待花开 2024-12-12 18:50:38

我也想知道区别,以下来自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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文