与客户形式的模板渲染注入模板内 [英] Template rendering with custome form inject inside Template

查看:73
本文介绍了与客户形式的模板渲染注入模板内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,

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.

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

And below is my form

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

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

Thanks,

推荐答案

方法1



你可以使用普通的File.ReadAllText方法将html读成字符串

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;
        }





然后创建一个ActionResult,用于将html作为json字符串返回,如下所示



and then Create an ActionResult for returning the html as json string like below

[HttpGet]
public ActionResult LoadHtml(int id)
{
var html=GetHtml("you html file path");
var result = new { Value = html };
return Json(result, JsonRequestBehavior.AllowGet);
}





使用客户端的jQuery调用操作并将html插入到您想要的容器中



Call the action by using jQuery from the client and insert the html in to a container you want

jQuery(document).ready(function(){


#buttonClick).click( function (){
var ServiceUrl = / YourController / LoadHtml;
var content ='';
("#buttonClick").click(function() { var ServiceUrl ="/YourController/LoadHtml; var content = '';


.support。 cors = true;
.support.cors = true;


这篇关于与客户形式的模板渲染注入模板内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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