ASP.NET MVC:视图不进行文件上传功能良好 [英] ASP.NET MVC: view does not function well for file upload

查看:157
本文介绍了ASP.NET MVC:视图不进行文件上传功能良好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想补充的上传文件我的看法里的领域。
我编辑我的视图模型,并添加下面一行到它:
        公共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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆