Click here to Skip to main content
15,793,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have 100's of HTML template(Basically HTML file from 3rd party with header, footer and body with many branding elements and a div called "container") and this is stored in a physical location in a Some server.

My requirement is to render this template by finding the div "container" inside the template and inject my form content into this div.

Sample template.

//logo and some content
<div id ="MainContent">
<div id ="MyContent">
<div id ="Footer">

And below is my form

 <form name="form1" method="post" action="1.aspx" id="form1"  autocomplete="off">
<input type="sumbit" value="submit">

This form should go inside the div MyContent and render.

I don't have control on template and it will not be part of my solution and it is dynamic it can change any time, but always have div called MyContent

Updated 18-Oct-13 0:33am

1 solution

Method 1

You can read html as string by using normal File.ReadAllText Method
public static string GetHtml(string path)
            string html = File.ReadAllText(path);
            return html;

and then Create an ActionResult for returning the html as json string like below
public ActionResult LoadHtml(int id)
var html=GetHtml("you html file path");
var result = new { Value = html };
return Json(result, JsonRequestBehavior.AllowGet);

Call the action by using jQuery from the client and insert the html in to a container you want
$("#buttonClick").click(function() {
var ServiceUrl ="/YourController/LoadHtml;
var content = '';
$.support.cors = true;
type: 'GET',
url: ServiceUrl,
async: true,
cache: false,
crossDomain: true,
contentType: "application/json; charset=utf-8",
dataType: 'json',
error: function (xhr, err) {
success: function (result, status) {

By using Render js also you can load template in to html
for more[^]
Hope this helps
Share this answer
charan49 10-Sep-13 6:32am    
Hi Jameel,

Thanks for your reply.

I don't want to insert template content(HTML) to a div in my Page.(As it is done above)

I want to insert my form content to a template div and render that.

charan49 12-Sep-13 6:16am    
Anybody has any suggestion for this?
Jameel VM 12-Sep-13 6:22am    
did you try Jsrender?
charan49 18-Oct-13 5:25am    
Hi Jameel, Jsrender also does the same thing.. Someone will push the Template(HTML page) with a div id =container into my server.. and i need to take that template and put my FORM content into this div and render.. So i dont have any control over the template..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900