Can someone help me with model validation on a HttpPostedFileWrapper object?
Model:
[Required(AllowEmptyStrings = false)]
public HttpPostedFileWrapper BlahFile { get; set; }
Controller:
[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>
}
Problem:
- Cannot see the “data-val*” attributes being added to the html.
- Does not set the unobtrusive validation off (red border on input box)
Notes:
- Other items in the Model are working fine with validation, its only the
<input type="file"/>that seems to be having problems. - Comes into the action method fine – (i.e – i can access the InputStream if i want).
- All scripts are referenced correctly (its working on normal text input’s)
Thanks in advance,
Just for anyone else coming across this question you can also do this –