剃刀支持通用的扩展方法 [英] Razor support of generic extension methods
问题描述
至于到的Razor视图引擎,说我想渲染 Html.TextBoxFor< SomeModel>(I => i.Name)
,它似乎并不该内嵌语法的工作原理是:
With regards to the Razor view engine, say I want to render Html.TextBoxFor<SomeModel>(i => i.Name)
, it doesn't seem that the inline syntax works as in:
@Html.TextBoxFor<SomeModel>(i => i.Name)
这似乎并没有工作,因为它除$ P $点一般为一个HTML标签。我可以用code块方法,但什么是输出的最佳方法的内容? HTML字符串从这个方法返回,做我的Response.Write,或者是有其语法,或者有什么方法呢?
This doesn't seem to work because it interprets the generic as an HTML tag. I could use a code-block approach, but then what's the best approach to output the content? The HTML string returned from this method, do I response.write it, or is there a syntax for it, or what's the approach?
感谢。
推荐答案
有,我已经找到致富剃刀明确解析(而不是试图找出该怎么做)四种方式:
There are four ways that I've found to get razor to explicitly parse (as opposed to trying to work out what to do):
- @(some code) (this is the method used by @Matt Hamilton)
- Html.Raw("some encoded text")
- <text>Some encoded text</text>
- @@
只有第一项将在这里工作。
Only the first of these would work here.
有上PluralSight 在剃刀和ASP.NET MVC的演练3.0 |交织在这个确切的主题code和标记部分。
There is a walkthrough on PluralSight in the Razor and ASP.NET MVC 3.0 | Intermingling code and markup section, on this exact subject.
这篇关于剃刀支持通用的扩展方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!