我有以下模型:
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
and System.ComponentModel.DataAnnotations
.
然后我在我的观点中将其呈现如下:
<h1>Edit @Model.Name</h1>
@using (Html.BeginForm("Edit", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" })) {
@Html.EditorForModel()
<div class="editor-lable">Image</div>
<div class="editor-=field">
@if (Model.ImageData == null)
{
@:None
}
else
{
<img width="150" height="150" src="@Url.Action("GetImage", "Product", new { Model.ProductID })" />
}
<div>Upload new image: <input type="file" name="Image" . /></div>
</div>
<input type="submit" value="Save" />
@Html.ActionLink("Cancel and return to List", "Index")
}
问题是,虽然[Required]
注释工作正常[HiddenInput]
字段实际上并没有隐藏。 html 源甚至没有显示隐藏属性。
为什么不是Html.EditorForModel
应用[HiddenInput]
归因于那些属性?有任何想法吗?
就我而言,我必须写[HiddenInput]
as [HiddenInput(DisplayValue=false)]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)