我有以下型号:
public class Product
{
[HiddenInput(DisplayValue = false)]
public int ProductID { get; set; }
[required(ErrorMessage="Please enter a product name")]
public string Name { get; set; }
[required(ErrorMessage="Please enter a description")]
[DataType(DataType.MultilineText)]
public string Description { get; set; }
[required]
[Range(0.01,double.MaxValue,ErrorMessage="Please enter a positive price")]
public decimal Price { get; set; }
[required(ErrorMessage="Please specify a category")]
public string Category { get; set; }
public byte[] ImageData { get; set; }
[HiddenInput(DisplayValue = false)]
public string ImageMimeType { get; set; }
}
我引用了System.Web.Mvc和System.ComponentModel.DataAnnotations.
我在这里提出如下:
Edit @Model.Name
@using (Html.BeginForm("Edit","Admin",FormMethod.Post,new { enctype = "multipart/form-data" })) {
@Html.EditorForModel()
@if (Model.ImageData == null)
{
@:None
}
else
{
}
@Html.ActionLink("Cancel and return to List","Index")
}
问题是当[必需]注释正常工作时,[HiddenInput]字段实际上并不隐藏. html源代码甚至没有显示隐藏属性.
为什么Html.EditorForModel没有将[HiddenInput]属性应用于这些属性?有任何想法吗?