Razor support of generic extension methods
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)
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 co开发者_如何学Cntent? The HTML string returned from this method, do I response.write it, or is there a syntax for it, or what's the approach?
Thanks.
How about:
@(Html.TextBoxFor<SomeModel>(i => i.Name))
Do parentheses help?
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.
There is a walkthrough on PluralSight in the Razor and ASP.NET MVC 3.0 | Intermingling code and markup section, on this exact subject.
精彩评论