有人可以帮助我在HttpPostedFileWrapper对象上进行模型验证吗?
型号:
[Required(AllowEmptyStrings = false)]
public HttpPostedFileWrapper BlahFile { get; set; }
控制器:
[HttpPost]
public ActionResult LoadBlahData(BlahModel blahModel)
{
if (!ModelState.IsValid)
return RedirectToAction("Index");
}
CSHTML:
@using (Html.BeginForm("LoadBlahData", "Admin", FormMethod.Post, new { @class = "blahhForm", enctype = "multipart/form-data", id = "uploadBlah" }))
{
<fieldset>
<legend>Upload Blah Information</legend>
@Html.LabelFor(x=>x.BlahFile, "Upload Blah file:")
<input size="26" class="uploader" type="file" name="BlahFile" />
<p><input class="ttButton" type="submit" value="Load Stuff" /></p>
</fieldset>
}
问题:
备注:
<input type="file"/>
似乎有问题。提前致谢,
答案 0 :(得分:0)
您尚未向元素添加任何数据属性。添加就像,
<input data-pk="1" size="26" class="uploader" type="file" name="BlahFile" />
并且不支持验证<input type="file"
答案 1 :(得分:0)
对于遇到此问题的其他人,您也可以这样做 -
<%: Html.TextBoxFor(x => x.BlahFile, new { type = "file" }) %>