The lack of an EditorFor file in asp.net mvc 3 seems like such a glaring omission I wonder: Is there some way that mvc handles file uploads that is just not publicized that well? As near as I can tell there is no built in way to handle file uploads.
I'm just curious if the file upload capability is in fact there and I'm just missing it, or if it does not exist at all.
This works great for me, provides client-side validation too.
CSHTML:
<div class="editor-label">
@Html.LabelFor(model => model.Image)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Image, new { type = "file" })
@Html.ValidationMessageFor(model => model.Image)
</div>
Model:
[Required("Image is required")]
public HttpPostedFileBase Image { get; set; }
No, but the following steps don't seem like too much work to me. Not to mention that you could write a custom editor template which will render a file input for a given property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With