[英]Using underscore templating with ASP.NET controls
I am trying to use underscores templating system in my project.我正在尝试在我的项目中使用下划线模板系统。 Now the issue is that we have a lot of server side (ASP.NET) controls as well that I would like to use.
现在的问题是我们还有很多我想使用的服务器端 (ASP.NET) 控件。 Is there any way to use the ASP.NET controls together with underscore templates?
有没有办法将 ASP.NET 控件与下划线模板一起使用?
I tried simulating a template as an aspx page to get the rendered html from there and then use the result but that seems like an overkill.我尝试将模板模拟为 aspx 页面以从那里获取呈现的 html,然后使用结果,但这似乎有点矫枉过正。
I am pretty new to templating so I have no idea about what to expect.我对模板很陌生,所以我不知道会发生什么。
EDIT:编辑:
What I meant was, is there any way I can have eg an ASP.NET button inside an underscore template?我的意思是,有什么方法可以让我在下划线模板中包含一个 ASP.NET 按钮?
The issue isn't with ASP.NET Controls (which use the runat="server"
attribute), but with ASP.NET's Render function syntax <% %>
.问题不在于 ASP.NET 控件(使用
runat="server"
属性),而在于 ASP.NET 的 Render 函数语法<% %>
。
See this earlier QA: How to use underscore/javascript templates in ASP.Net MVC views the solution is to configure underscore.js to use a different delimiter:请参阅较早的 QA: 如何在 ASP.Net MVC 视图中使用下划线/javascript 模板,解决方案是配置 underscore.js 以使用不同的分隔符:
This:这个:
_.templateSettings = {
interpolate: /\{%=(.+?)%\}/g,
escape: /\{%-(.+?)%\}/g,
evaluate: /\{%(.+?)%\}/g
};
...will let you use {% %}
as delimiters instead of <% %>
. ...会让你使用
{% %}
作为分隔符而不是<% %>
。
I just thought that it might help someone.我只是认为它可能会帮助某人。 One of the controls I wanted to use was a devexpress grid in my view.
在我看来,我想使用的控件之一是 devexpress 网格。 Now I could have done a "view source" on the grid and copied the rendered html to generate the view.
现在我可以在网格上完成一个“查看源代码”并复制呈现的 html 以生成视图。 However, I decided to create an aspx page and did an ajax call to the aspx page and displayed the resultant html in the view.
但是,我决定创建一个 aspx 页面并对 aspx 页面进行 ajax 调用并在视图中显示结果 html。 I was hoping there would be a better way to do this.
我希望有更好的方法来做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.