类型对象上的 ScaffoldColumn 属性

发布于 2024-09-15 18:44:31 字数 858 浏览 2 评论 0原文

似乎要跳过成员进入视图,您可以在模型中将 ScaffoldColumn 属性设置为 false,

[ScaffoldColumn(false)]
public object Id { get; set; } 

但在这里我看到 Id 是对象类型。这是唯一的方法吗?我尝试过,

[ScaffoldColumn(false)]
public int Id { get; set; } 

但没有成功。我如何防止基元类型上的脚手架,例如 int、long 等。

编辑

我已经定义了我的模型,因为

public class Department
{
[ScaffoldColumn(false)]        
        public int Id { get; set; }

        [Required(ErrorMessage="Name is required")]
        [StringLength(25)]
        [DisplayName("Name")]
        public string Name { get; set; }

        public bool Active { get; set; }
}

我有一个具有操作 Create 的控制器。当我右键单击创建操作并选择添加视图并使用此模型创建强类型视图时,它会创建一个视图,但还会添加一个 Id 文本框

<%: Html.TextBoxFor(model => model.Id)%>

,我认为它不应该有

It seems that to skip a member to come on a View you can set ScaffoldColumn attribute to false in your model

[ScaffoldColumn(false)]
public object Id { get; set; } 

but here i see that Id is of object type. Is this the only way? I tried with

[ScaffoldColumn(false)]
public int Id { get; set; } 

but it didn't work. How can i prevent scaffolding on a primitive type e.g. int,long etc.

Edit

I have define my model as

public class Department
{
[ScaffoldColumn(false)]        
        public int Id { get; set; }

        [Required(ErrorMessage="Name is required")]
        [StringLength(25)]
        [DisplayName("Name")]
        public string Name { get; set; }

        public bool Active { get; set; }
}

I have a controller having action Create. When i right click on create action and select add view and create a strongly type view with this model it creates a view but also adds a textbox for Id

<%: Html.TextBoxFor(model => model.Id)%>

which i suppose it shouldn't have

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

黯然#的苍凉 2024-09-22 18:44:31

ScaffoldColumn 仅更改实际使用 MVC 2 中引入的默认模板化视图系统。它不会影响 MVC 附带的 Visual Studio 向导。

要改变这一点,您需要编辑 T4 模板, 有点像这样

不过我不会打扰。如果您想要 MVC 2 中的脚手架,我认为最好使用默认模板化视图,而不是“添加视图”脚手架,即代码生成。

ScaffoldColumn only changes the behavior of methods like Html.DisplayForModel() which actually use the default templated views system introduced in MVC 2. It does not affect the Visual Studio wizards that ship with MVC.

To change that, you need to edit the T4 templates, somewhat like this.

I wouldn't bother, though. If you want scaffolding in MVC 2, I think it's better to use default templated views than the "Add View" scaffolding, which is code generation.

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