flyingfisch flyingfisch - 2 months ago 53
ASP.NET (C#) Question

Embedding SVG in ASP.net page

I would like to embed svg directly into my ASP.net-MVC view so that the output looks something like this:

<html>
<body>
<svg> ... </svg>
</body>
</html>


With PHP I would do this like so:

<? include('image.svg'); ?>


I tried
@Html.Partial('image.svg')
but got an error. Is there a way to fix this or another method I can try?

Answer

Embed your SVG into a cshtml view file instead of a .svg file, then you should be able to use @Html.Partial to render it.

Your partial would then look like

@Html.Partial("~/Views/pathtosvg/svg.cshtml")

Comments