Search code examples
asp.net-corerazor

How do I display SVG in .cshtml


I am trying to display .svg image on my .cshtml page.

Status404.cshtml

@inject Context Session
@{
    Layout = "";    

}

<img src="/workspace/src/Application/wwwroot/img/404.svg" alt="404page"/>

@if(Session.CurrentUser.Language=="ka"){
    <p><ქართული ტექსტი</p>
}

@if(Session.CurrentUser.Language=="en"){
    <p><ENG TEXT HERE</p>
}

RESULT:

result

I tried creating a partial view(renamed .svg to .cshtml) like 404Partial.cshtml and then including it in .cshtml like this :

@await Html.PartialAsync("/workspace/src/Application/Views/404Partial.cshtml");

But it couldn't find the view.


Solution

  • After looking at your folder structure, this is the tag and path you need to use

    <object type="image/svg+xml" data="~/img/404.svg"> </object>