I have image references that look like this: src="../../Images/backup5.jpg"
. This matches the project structure. Although in the published version, these links do not work. If i change the path to src="../Images/backup5.jpg"
by removing a "../" the image will display correctly. What is the correct way to reference these images so they work in both the development version and in the published version?
Follow up, how should this look when used in css as a background:
attribute?
In ASP.NET MVC, ViewModel is a class that contains the fields which are represented in the strongly-typed view. It is used to pass data from controller to strongly-typed view.
In an ASP.NET MVC application, a URL corresponds to a controller action instead of a page on disk. In a traditional ASP.NET or ASP application, browser requests are mapped to pages. In an ASP.NET MVC application, in contrast, browser requests are mapped to controller actions.
2 ways
<img src="@Url.Content("~/Images/trash.svg")"> OR
<img src='/images/trash.svg'>
You should be using the Url.Content
helper with the tilda ~
marker (which resolves to the root of the application):
src="@Url.Content("~/Images/backup5.jpg")"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With