类型对象上的ScaffoldColumnColumn属性 [英] ScaffoldColumn attribute on type object

查看:95
本文介绍了类型对象上的ScaffoldColumnColumn属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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; } 

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

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; } 

但是没有用.我如何防止原始类型的脚手架例如int,long等.

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

修改

我已将模型定义为

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添加一个文本框

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)%>

我认为它不应该

推荐答案

ScaffoldColumn 仅更改实际上使用Html.DisplayForModel()之类的方法的行为.="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html" rel ="nofollow noreferrer"> MVC 2中引入的默认模板视图系统.它不会影响MVC附带的Visual Studio向导.

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.

要更改此设置,您需要编辑T4模板,

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

不过,我不会打扰.如果您想在MVC 2中使用脚手架,我认为使用默认的模板视图比添加视图"脚手架(代码生成)要好.

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.

这篇关于类型对象上的ScaffoldColumnColumn属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆