将 ~/Content 中的静态 html 文件包含到 ASP.NET MVC 视图中 [英] Including static html file from ~/Content into ASP.NET MVC view

查看:21
本文介绍了将 ~/Content 中的静态 html 文件包含到 ASP.NET MVC 视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有母版页,其中包含有关站点版权的一些信息和一些联系信息.我想把它从母版页中取出并放在一个静态文件中(出于某种原因,这些文件必须放在 ~/Content 文件夹中).有没有一种方法可以在我看来像

I've got master page in my project, which contains some information about site copyright and some contact info in it. I'd like to take it out of master page and place it in a static files (for some reason, these files must be placed in ~/Content folder). Is there a way that I can tell in my view something like

<% Html.Include("~/Content/snippet.html") %>   // not a real code

?

推荐答案

最好使用局部视图(即使它只包含静态文本)并将其包含在 Html.Partial 帮助器中.但如果你坚持:

You are better off using a partial view (even if it only contains static text) and include it with the Html.Partial helper. But if you insist:

<%= File.ReadAllText(Server.MapPath("~/Content/snippet.html")) %>

这篇关于将 ~/Content 中的静态 html 文件包含到 ASP.NET MVC 视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆