Images not rendering in localhost - asp.net-mvc

I have images sitting within my project root at Data\Images\articles. I am trying to render the image using the code below in MVC:
<img src="#Url.Content(Model.Image)" alt="Image" />
It's not displaying the image, however the rendered html code is correct.
<img src="/Data/Images/Articles/16fd7bc5-3bac-474a-a806-b8d72b974960.PNG" alt="Image">
I am running the project from Visual studio server, not through IIS. Any idea what I am doing wrong here?

Different file name was generating as compare to what was expecting in logic causing 404 error when validating the image file name

Related

Get Content Folder Images In Areas Admin View ASP.NET MVC

I want To get Images in Project/Areas/Admin/Index ..
and images in Project/Content Folder
so it show error when i use
<img src="#item.ProductImagePath" />
error
GET https://localhost:44378/Admin/Home/Content/dress3.jpg ERROR..
it find image on Admin but images are in content folder
It Added Admin in Image Path
here the image of directory and img tag
I think you use wrong routes.
for example, this image in admin areas and you can see it:
https://take-car.ru/areas/admin/MxPBksiUmnA.jpg

How to use images on the error pages(404, 500 ...)?

How to use images on the error pages(404, 500 ...)?
Can I use images from a folder "assets" ?
I need to compile them or no?
You can create an image folder within the public folder, in the root of your application, and then from there, you can access them by referencing it directly.
An example on the 404 html file.
<div class="dialog">
<div>
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
<img src="images/01.jpg" alt="">
</div>
public/images/ contains the 01.jpg image file.
Another idea that you could consider is having the 404.html and 500.html located on Amazon S3. Something like that would accomplish you having your picture(s) available on S3 with the entire page itself.
Then if you are using a service like Heroku to host your application, you can change the ERROR_PAGE_URL variable to point to your error page on S3.
If you can't or don't want to store the images anywhere else, you can use Base64 encoding to have the images inside the HTML code of the error page itself. You can use any Base64 encoder such as https://base64.guru/converter/encode/image

How to add image in pdf file

I have used this blog for adding a dynamic pdf in my project. when i am tryng to add a image than it is compelling me to have a Image folder in C:\ . How can i add a image from project.
This appears to be using a html view page to render the PDF so you can just use a normal img tag like you would in any html page.
With razor syntax you can do something like this:
<img alt="" src="#Url.Content("~/Content/Images/mypic.png")" />
I believe this may solve your issue. Essentially you want to specify the full web url as the src of the img, for example:
<img alt="" src="www.example.com/images/mypic.png" />

PDFkit doesn't display pictures in PDF

Rails 2, PDFkit 0.5.0
Im generating a PDF from a View in Rails 2 with PDFkit and everything works fine. The only thing which doesn't work is displaying pictures in the pdf.
When I look at the View in the Browser, the picture is there but its missing in the PDF. There is only a placeholder existing in the PDF.
The image_tag is looking like this:
<%= image_tag('plus.gif') %>
I also tried to realize it with a css-file but it doesn't work either.
Any ideas?
Because of the way that wkhtmltopdf works you need to specify the full path to any assets (JS, CSS, images etc), including the domain name.
This won't work:
<img src="/images/foo.png" />
This will:
<img src="http://example.com/images/foo.png" />
One workaround is to set an explicit asset host, even if it's the same server as your app is running on (see the AssetTagHelper documentation for details). Another would be to specify the hostname in the image_tag.
Instead of putting the full path each time, you can add a base tag to the head section.
<base href="http://mydomain.com" target="_blank" />

Where do you store images for asp.net mvc projects and how do you reference them from site.master

I have a new asp.net mvc project and i am trying to figure out the best place to store images and also how i would reference them from site.master (in cases where i have a header images that i want to show up on all pages).
Suggestions or best practices?
What I generally do is create an "Images" folder inside my Content folder. Where you place your images is really up to you, as long as you are consistent.
Referencing these images from your Site.Master is the same as if you referenced it from any view:
<img src="/Content/Images/mylogo.png" />
<img src="#Url.Content("~/Content/Images/logo.png")" />
Using this in a Razor view on MVC 5. Images are stored in /Content/Images.
<%=Html.Image("~/Content/Images/xxx.png")%>
This resolves from wherever you are in the site hierarchy. Html.Image is a part of the the Microsoft.Web.Mvc futures assembly.
or in mvc2:
<img src="<%: Url.Content("~/Images2/landingMain/safety.png") %>" alt="safety" />
U must put all your images in Content Folder like :-
Content-->Images-->.IMG files and
same as style sheet files
Content Folder like Content-->.css hence it easily load the images and css otherwise it is not executed in proper manner.

Resources