类型对象上的ScaffoldColumnColumn属性 [英] ScaffoldColumn attribute on type object
问题描述
似乎要跳过某个成员进入视图,可以在模型中将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
仅更改实际上使用
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.
不过,我不会打扰.如果您想在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屋!