I just edited my route for a user details page to look like this:
routes.MapRoute(
"UserDetails", // Route name
"{controller}/{action}/{id}/{title}", // URL with parameters
new { controller = "Users", action = "Details", id = UrlParameter.Optional, title = UrlParameter.Optional } // Parameter defaults
);
Now when my url looks like this: localhost/Users/Details/1/ShawnMclean
Images do not load both from the controller and the site.master. (no idea why the css and javascript had correct urls though). If the url is localhost/Users/Details/1
then everything loads fine.
My img in site.master
and Details.aspx
looks like this in the old url:
<img src="../../Content/Images/logo3.png" />
but when the url gets an additional parameter, the image is actually located at ../../../Content/Images/logo3.png
Is there a way to make images and other static content's url change?
Here we will learn that to display image in ASP.NET MVC. Step 1 - Go to SQL Server Management System and execute the following script. Step 2 - Go to Visual studio and add a new project.
So let’s look at how to upload and retrieve images in ASP.NET Core MVC. Save the image to the server file. Retrieve uploaded back to the view. Delete image record and file. In Visual Studio 2019, Go to File > New > Project (Ctrl + Shift + N). Select Asp.Net Core Web Application template. Once you provide the project name and location.
Folder Location to keep Static Files (Images, CSS and JS files) in ASP.Net Core In the below screenshot, three folders CSS, Images and Scripts have been created inside the wwwroot folder. The wwwroot folder is the default folder provided by ASP.Net Core for storing all the Static files such as Image files, CSS files and JavaScript JS files.
An ASP.NET Image server control is a control that displays an image on the web page. The image is sourced from either a location on the server or from a URL on the internet. Why did I use the term server control?
Try linking your images like this:
<img src="/Content/Images/logo3.png" />
or if that doesn't work you could always use a helper for your links
<img src="<%= Url.Content("~/Content/Images/logo3.png") %>" />
one other way could be
<img src="@Url.Content("~/Content/Images/logo3.png")" />
You can try using a helper:
<img src='<%= Url.Content( "~/Content/Images/pic.jpg" ) %>' alt="My Image" />
You can try this,
<a href="/"><img src="<%=Url.Content("~/Content/Images/logo.png")%>" alt="logo" title="Logo" /></a>
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