render .htm page into .aspx page
in my .aspx page i want to render a .htm page which has some data in .aspx page i have:
<% Html.RenderPartial("/Views/Templates/HTML_Temp.htm"); %>
but this gives runtime error:
Server Er开发者_高级运维ror in '/' Application.
There is no build provider registered for the extension '.htm'. You can register one in the section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.
how to resolve this problem...please help
try this instead:
<%= File.ReadAllText(Server.MapPath("/Views/Templates/HTML_Temp.htm")) %>
<%= System.IO.File.ReadAllText(Server.MapPath("~/Views/Templates/HTML_Temp.htm")) %>
Use #include
The simplest way to put some HTML content in your containing page is by using a server include with #include
:
<!-- #include file="../Templates/HTML_Temp.htm" -->
// for relative paths
or
<!-- #include virtual="/Views/Templates/HTML_Temp.htm" -->
// for virtual paths
A better way for Asp.net up to 2.0
A better way would of course be to rename your HTML files to ASCX and create a common CS file that doesn't have any particular functionality. Use this same CS file (class relation) with all you newly created ASCX files.
A better way for Asp.net 2.0 and above
Create a master page (or multitude of them; if you're in 3.0 or higher they can be nested as well) that includes common content and develop other pages on top of your master(s).
精彩评论