Share via


Import .svg with razor syntax

Question

Wednesday, October 31, 2012 8:51 AM

Hi,

I want to import the conten of a .svg file with razor syntax. I tried the @RenderPage() Method but it didn't worked because of the file extension. Is there any way to import the content of a file with razor syntax? It would really help me.

All replies (3)

Wednesday, October 31, 2012 9:35 AM âś…Answered

@Html.Raw(File.ReadAllText(Server.MapPath("~/test.svg")))

Wednesday, October 31, 2012 9:42 AM

If you want to use the RenderPage method you could embed your .svg file into a cshtml page and pass it as parameter to the RenderPage method.

e.g. create a _image.cshtml page with this tag only

<object data="yoursvgfile.svg" height="160" width="160" type="image/svg+xml"></object>

and import it in your main page with

@RenderPage("_image.cshtml")

For a list of different techniques for embedding  svg files look at SVG In HTML Pages.


Wednesday, October 31, 2012 10:00 AM

Thanks a lot.

@Html.Raw(File.ReadAllText(Server.MapPath("~/test.svg")))

This worked!! 

I already tried the answer of GmGregori but that didn't display the .svg, it offers it as download.

However, thanks to all.