简体   繁体   English

静态html页面中的mvc路径图像

[英]mvc path image in static html page

someone knows how to manage path image in static html? 有人知道如何在静态HTML中管理路径图像? The problem is how to specify the images path INSIDE THE STATIC HTML so to work as online as visual studio localhost 问题是如何指定图像路径INSIDE THE STATIC HTML,以便像visual studio localhost一样在线工作

Example : i have a home page and inside some static html page 示例:我有一个主页,并在一些静态html页面内

@Html.Raw(File.ReadAllText(Server.MapPath("~/custom_directory/home/static_page.html")))

INSIDE THE STATIC HTML : 1. if i use relative path : custom_directory/home/img/image1.jpg It works online but it doesnt work in visual studio localhost 在静态HTML中:1。如果我使用相对路径:custom_directory / home / img / image1.jpg它可以在线工作,但它在visual studio localhost中不起作用

  1. if i use / : /custom_directory/home/img/image1.jpg It works in visual studio localhost but it doesnt work online 如果我使用/:/custom_directory/home/img/image1.jpg它适用于visual studio localhost但它不能在线工作

There's a manner to work in both situation? 在这两种情况下都有办法吗?

Thanks 谢谢

您需要将Url.Content()辅助方法与根应用程序目录中的相对URL一起使用,因此无论基本目录名称是什么,它都可以在localhost和生产中使用:

@Url.Content("~/custom_directory/home/img/image1.jpg")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM