已尝试过 W3 学校列出的所有嵌入方法以及更多方法。即使提供了宽度和高度,资源管理器也会显示不正确的大小,chrome和firefox只是提示下载。使用 Visual Studio 2010 内置的开发服务器,可能需要添加 mime 类型来支持,但不知道在哪里。
SVG 文件位于我的内容文件夹中,我正在视图中创建 html,其中 ImageFileName 是“filename.svg”:
<object data="/Content/ExternalCats/@RootCat.ImageFileName" type="image/svg+xml"></object>
or
<embed src="/Content/ExternalCats/@RootCat.ImageFileName" width="300" height="100"
type="image/svg+xml"
pluginspage="http://www.adobe.com/svg/viewer/install/" />
您可以尝试嵌入<svg>
直接进入 HTML。现代浏览器支持它:
@Html.Raw(File.ReadAllText(Server.MapPath("~/content/externalcats/" + RootCat.ImageFileName)))
或使用正确的 MIME 类型提供 SVG (image/svg+xml
):
public ActionResult Svg()
{
return File(Server.MapPath("~/content/test.svg"), "image/svg+xml");
}
进而:
<object data="@Url.Action("svg")" type="image/svg+xml">
<embed src="@Url.Action("svg")" type="image/svg+xml"/>
</object>
或者如果您使用的是 IIS 7.0+,您可以定义静态 MIME 映射 http://www.iis.net/ConfigReference/system.webServer/staticContent/mimeMap与.svg
扩大:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
</system.webServer>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)