Embedding SVG in ASP.net page

时光毁灭记忆、已成空白 提交于 2019-12-21 12:49:55

问题


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?


回答1:


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")




回答2:


Renaming SVG files and using Html.Partial should do the trick, but I didn't like to be renaming files in order to achieve it. So, this way, you can keep your files as they are.

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



回答3:


Can you use just file include same as php file?

Example:

<!--#include file="image.svg"-->

This syntax should work similar to php include, but for asp.net



来源:https://stackoverflow.com/questions/29478812/embedding-svg-in-asp-net-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!