视图模板code标签 - asp.net mvc的 - REGD [英] view template code tags - asp.net mvc - regd

查看:123
本文介绍了视图模板code标签 - asp.net mvc的 - REGD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是℃之间的差异;%%>和<%:%>在asp.net MVC视图引擎的上下文。在MVC2本书它给出如下:

What is the difference between <% %> and <%: %> in context of asp.net MVC view engine. In the MVC2 book it's given as follows:


  • &LT;%%> code掘金执行code时查看模板呈现

  • &LT;%:%> code掘金执行其中包含​​的code,然后渲染结果到模板的输出流

当使用第一和时使用的第二λ

When to use the first and when to use the second?

推荐答案

这本书几乎是正确的:

&LT;%%GT; code掘金执行code时查看模板呈现。所以,如果你把一个呼叫功能&LT; D​​IV&GT;&LT;%MYFUNC()%&GT;&LT; / DIV&GT; 的你功能将在以后的渲染时间执行打开标签,如果格被渲染,但结束标记之前呈现。该函数可以做任何你想要的,检查一些条件和失败,例外,设置一些变量,使用 HttpContext.CurrentContext.Response.Write (或只是回复于在web表单)写入响应流。

<% %> code nuggets execute code when the View template renders. So if you put a call to function <div><% MyFunc() %></div> the you function will be executed at the rendering time after opening tag if div was rendered but before closing tag was rendered. The function may do anything you want, check some conditions and fail with exception, set some variables, use HttpContext.CurrentContext.Response.Write (or just Response.Write in webforms) to write to response stream.

&LT;%:%&GT; code掘金执行包含在其中的code,然后呈现结果的 HTML EN codeD 以模板的输出流。即它是一样的&LT;%HttpServerUtility.HtmlEn code(HttpContext.CurrentContext.Response.Write(MYFUNC()))%GT;

<%: %> code nuggets execute the code contained within them and then render the result html encoded to the output stream of the template. i.e it is the same as <% HttpServerUtility.HtmlEncode(HttpContext.CurrentContext.Response.Write(MyFunc()))%>

&LT;%=%&GT; code掘金执行包含在其中的code,然后呈现结果的无需HTML编码到模板的输出流。即它是一样的&LT;%HttpContext.CurrentContext.Response.Write(MYFUNC())%GT;

<%= %> code nuggets execute the code contained within them and then render the result without html encoding to the output stream of the template. i.e it is the same as <% HttpContext.CurrentContext.Response.Write(MyFunc())%>

--- MYFUNC()在最后两种情况应返回一个字符串。它也可以是一些属性的引用视图模型或任何其他code金块计算结果为字符串。

---MyFunc() in last two cases should return a string. It can also be a reference to some property of ViewModel or any other code nugget that evaluates to string.

这篇关于视图模板code标签 - asp.net mvc的 - REGD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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