问题描述
我有一个模特
class Address {
public int AddressID {get;set;}
public string Street {get;set;}
public string City {get;set;}
public string State {get;set;}
public int ZipCode {get;set;}
}
在我看来
@Html.LabelFor(model => model.Address)
(假设地址是另一个模型内部的复杂属性)
@Html.LabelFor(model => model.Address)
(assuming Address is a complex property inside another model)
我为每个Address属性获得一个标签,所以我得到:
I get a label for every one of Address properties, so I get:
AddressID:
AddressID:
街道:
城市:
状态:
邮政编码:
问题是,我不想显示ID属性,我尝试了以下两个注释:
problem is, I don't want the ID property to show up, I tried these two annotations:
[Display(AutoGenerateField = false)]
[HiddenInput(DisplayValue = false)]
但是第一个由于某种原因没有执行任何操作,并且HiddenInput不断显示一条红色的波浪线,不确定它们是否都使用相同的System.ComponentModel.DataAnnotations
程序集
but the first one doesn't do anything for some reason, and the HiddenInput keeps getting a red squiggly line, not sure if they both use the same System.ComponentModel.DataAnnotations
assembly
推荐答案
实际上才找到答案.
[HiddenInput(DisplayValue = false)]
可行,但我必须添加:
[HiddenInput(DisplayValue = false)]
works but I had to add:
using System.Web.Mvc;
这篇关于数据注释隐藏属性/字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!