如何在Mvc5中上传和显示图像

问题描述:

大家好,



我还是很新的mvc,我希望能够使用html文件上传控件上传图片并为用户显示图片同时,请问我如何实现这一目标?

Hello everyone,

I am still very new to mvc, i want to be able to upload picture using html file upload control and display the image for the user at the same time, please how do i achieve this?

您可能会对阅读以下论坛帖子感兴趣: HTTP://forums.asp。 net / t / 1976497.aspx?ASP + Net + MVC + 5 +上传+图片+保存+ +数据库+创建+缩略图+和+显示+ +视图 [ ^ ]。



另外,MVC只是另一个框架,所以你在其他框架中使用的代码也可以像在MVC中一样工作。这是文档 [ ^ ]用于在网页中编写相同的代码。请记住,图像毕竟是文件,因此任何可以上传文件的代码也可以上传图像。



显示图像需要一个简单的< img>< / img> 元素。您可以将上传图像的名称传递给它,它将在浏览器中显示图像。
You might get interested in reading the following forum thread: http://forums.asp.net/t/1976497.aspx?ASP+Net+MVC+5+Upload+Image+Save+to+Database+Create+Thumbnail+and+Display+in+View[^].

Also, MVC is just another framework, so the code you use in other framework would work just the way it would work in MVC too. Here is a document[^] for writing the same code in Web Pages. Remember, images are files after all so any code that can upload the file can also upload the image.

Displaying the image requires a simple <img></img> element. You can pass the name of the uploaded image to it and it will display the image inside your browser.