如何上传图片在ASP.NET MVC 3 [英] How can I upload pictures in ASP.NET MVC 3

查看:180
本文介绍了如何上传图片在ASP.NET MVC 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个网页,我可以上传图片,并在同一时间将他们的页面。

I want to create a page where I can upload pictures and at the same time bring them to the page.

例如:我有指标,addpictures在查看图片控制器

for example: I have a picture controller which has Index, addpictures in View.

谁能帮帮我吗?

我是初学者,所以这将是巨大的,如果你想尽可能简单写。
先谢谢了。

I am a beginner, so it would be great if you'd write as simple as possible. Thanks in advance.

推荐答案

您可以看看的的以下博客帖子了有关在ASP.NET MVC上传文件的教程。

You may take a look at the following blog post for a tutorial about uploading files in ASP.NET MVC.

借助路径类是在系统中定义.IO命名空间,所以你必须使该进的范围。

The Path class is defined in the System.IO namespace so you will have to bring that into scope.

如果您希望能够以显示上传的文件,你将不得不将其存储在比对App_Data一些其他的文件夹中。文件不是由从该文件夹的客户端直接访问。例如,你可以使用Content文件夹相反。 < IMG SRC:; IMG> 标签一旦你的文件出现在服务器上的这个文件夹中,你可以从视图中使用&LT引用它=@ Url.Content(〜/内容/ someimage.jpg)/ >在那里你可以在文件的名称传递从上传操作的视图。

If you want to be able to show the uploaded file you will have to store it in some other folder than the App_Data. Files are not directly accessible by clients from this folder. You could for example use the Content folder instead. Once you get the file appear in this folder on the server you could reference it from the view using the <img> tag: <img src="@Url.Content("~/content/someimage.jpg")" /> where you could pass the name of the file to the view from the upload action.

这篇关于如何上传图片在ASP.NET MVC 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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