c# - 是否有一个属性可以与 ASP.NET MVC 3 一起使用来防止模型字段自动包含在我的 View 中?

标签 c# asp.net-mvc asp.net-mvc-3 attributes razor

是否有一个属性可以与 ASP.NET MVC 3 一起使用来防止模型字段自动显示在我的 View 中?我的意思是我有如下类:

public class EntityBase
{
    public int ID { get; set; }
    //more fields...
}

public class TestEntity : EntityBase
{
    public string TestEntityName { get; set; }
    //more fields...
}

我了解 System.ComponentModelSystem.ComponentModel.DataAnnotations 中用于强制验证的所有属性 - Required StringLength 等 - 但是当我从 Visual Studio 创建 View 时,是否可以使用它来阻止某些字段显示在 View 中?我项目的所有模型类都继承自 EntityBase,但我不希望 EntityBase 的任何字段在 View 上可见。我使用 Razor 作为我的 ViewEngine,以防万一。

TIA,

类吉

最佳答案

使用脚手架列:

[ScaffoldColumn(false)]

关于c# - 是否有一个属性可以与 ASP.NET MVC 3 一起使用来防止模型字段自动包含在我的 View 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6782888/

相关文章:

c# - 如何在 C# 中获取 itextSharp 表格单元格的高度?

c# - System.Threading.Thread 在 .NET Core 中的含义与在 .NET Framework 中的含义相同吗?

asp.net - 如何将 razor 变量作为参数传递给 jquery 函数

c# - 在 C# 中执行基于存储过程的查询后,如何为 CommandText 重新使用 SqlCommand 对象?

asp.net-mvc-3 - ASP.NET MVC 3、RavenDB 和 Autofac Issue Plus 2 其他 Autofac 问题

c# - Visual Studio 2008 无法识别 Lambda 表达式语法

c# - 为什么 int.Max+ int.Max = -2

c# - 从 MVC Web 应用程序访问共享文件夹被拒绝

javascript - Javascript 中的全局数组范围问题

c# - 如何在 ASP.NET MVC Url.Action 中使用 C# nameof()