【发布时间】:2010-08-18 08:07:24
【问题描述】:
考虑以下设置:
型号:
public class Product
{
[ReadOnly(true)]
public int ProductID
{
get;
set;
}
public string Name
{
get;
set;
}
}
查看:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<MvcApplication4.Models.Product>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%= Html.EditorForModel() %>
</asp:Content>
控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new Product
{
ProductID = 1,
Name = "Banana"
});
}
}
结果是这样的:
我期待ProductID 属性不能通过ReadOnly(true) 属性进行编辑。这支持吗?如果没有,有什么方法可以提示 ASP.NET MVC 我的模型的某些属性是只读的?我不想通过[ScaffoldColumn(false)] 隐藏ProductID。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-2 readonly-attribute