如何在ASP.NET MVC视图中使用图像标记? [英] How to use image tag in ASP.NET MVC view ?

查看:63
本文介绍了如何在ASP.NET MVC视图中使用图像标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net mvc视图中使用图片标签?



这不起作用:

< img src = @ F:\ Picture\Pics\123.jpg/>



但我需要使用本地目录中的图片。



我尝试过:



如何在asp.net mvc中使用图片标签查看?



这不起作用:

< img src = @F:\ Picture \ Pics \ 123。 jpg/>



但我需要使用本地目录中的图片。

解决方案

正如您所说的那样F:是您的本地驱动器...您如何期望来自世界各地的任何用户都可以访问您的F:驱动器...事实上您应该对这些选项感到害怕!

你可能错过了互联网上的一些东西...

当用户打开你的页面时,按原样下载用户的机器并解释它们,而不再需要的Intera与服务器的关系(除了一些内容)。所以F:将被解释为用户的本地驱动器,甚至用户都有F:驱动器,可能你的图像不在那里...



在使用互联网时你必须使用 URI [ ^ ]识别资源,如图像。并且该URI必须指向一些可以公开访问的资源......在您的情况下,它必须指向您网站的某些部分...

 <   img     src   =  // mysite / images / 123.png    alt   =  123   /  >  

从ASP.NET MVC控制器返回图像 [ ^ ]

how to use image tag in asp.net mvc view ?

this is not working :
<img src=@"F:\Picture\Pics\123.jpg" />

but i need to use an image from my local directory.

What I have tried:

how to use image tag in asp.net mvc view ?

this is not working :
<img src=@"F:\Picture\Pics\123.jpg" />

but i need to use an image from my local directory.

解决方案

As you correctly stated F: is your local drive... How do you expect that any users from all over the world would have access to your F: drive... In fact you should be terrified of the options!
You probably missed some points of the internet thingy...
When user opens a page of yours the page - as-is - downloaded the the user's machine and interpreted their, without any more interaction with the server (except maybe some content). So F: will be interpreted as local drive of the user, and even user has F: drive, probably your image not there...

When working with internet you have to use URI[^] to identify resources, like images. And that URI must point to some openly accessible resource... In you case it must point to some part of your site...

<img src="//mysite/images/123.png" alt="123"/>


Returning An Image From ASP.NET MVC Controller[^]


这篇关于如何在ASP.NET MVC视图中使用图像标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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