Html.EditorForModel和编辑隐藏元素 [英] Html.EditorForModel and Hiding element from Edit

查看:595
本文介绍了Html.EditorForModel和编辑隐藏元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code渲染使用ASP.NET MVC 3我的模型编辑器,它的作品完美,除了我不希望用户看到或编辑的ID区域我的对象。

I'm using the following code to render an editor for my model using ASP.NET MVC 3, it works perfect, except for I don't want the user to see or edit the "Id" field in my object.

<% using (Html.BeginForm())
   { %>
    <%: Html.ValidationSummary(true, "Your input has errors, please correct and try again") %>
    <%: Html.EditorForModel(Model)%>

    <input type="submit" value="Update" />
<% } %>

在我的模型的ID字段我有以下

In my model for the ID Field I have the following

[Display(AutoGenerateField = false)]
public int Id{ get; private set; }

这是授予我的想法基于AutoGenerateField参数的说明会工作。然而,这是行不通的。我不希望有建全的编辑只为这一个小小的怪异....

Which granted is what I thought would work based on the description of the "AutoGenerateField" parameter. However this isn't working. I don't want to have to build the whole editor just for this one little oddity....

推荐答案

使用 [ScaffoldColumn(假)] 隐藏字段

这篇关于Html.EditorForModel和编辑隐藏元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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