ASP.NET MVC:视图不进行文件上传功能良好 [英] ASP.NET MVC: view does not function well for file upload
问题描述
我想补充的上传文件我的看法里的领域。
我编辑我的视图模型,并添加下面一行到它:
公共HttpPostedFileBase的ImageUrl {搞定;组; }
然后我在下面帮手文件上传:
I'm trying to add upload a file field inside my Views. I edited my ViewModel and added below line to it: public HttpPostedFileBase ImageUrl { get; set; } Then I added below helper for file upload:
@Html.EditorFor(model => model.ImageUrl)
我也改变了我的表单辅助函数是这样的:
I also changed my form helper like this:
@using (Html.BeginForm("Create", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
但它显示了文件的内部字段,当我跑我的看法:
However it shows internal fields of file when I run my view:
我已经错过了导致这种情况?
What I have missed that lead to this situation?
推荐答案
请你的模型对象上确保您的ImageUrl属性如下所示:
Make sure your ImageUrl property on your model object looks as follows:
[DataType(DataType.Upload)]
public HttpPostedFileBase ImageUrl { get; set; }
然后,在你看来,只需使用editorfor HTML辅助按正常
And then, in your view, just use the editorfor HTML helper as per normal
@Html.EditorFor(m => m.ImageUrl)
这篇关于ASP.NET MVC:视图不进行文件上传功能良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!