Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

Thanks.

like image 712
Brian Mains Avatar asked Feb 11 '11 04:02

Brian Mains


People also ask

What is the extension of razor page?

The Razor syntax consists of Razor markup, C#, and HTML. Files containing Razor generally have a . cshtml file extension.

What is the file extension for using Razor view with Visual Basic syntax?

Razor allows you to write a mix of HTML and server-side code using C# or Visual Basic. Razor view with visual basic syntax has . vbhtml file extension and C# syntax has . cshtml file extension.

What is razor in MVC why it is used?

Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML.

What is razor page in MVC?

Razor Pages is a newer, simplified web application programming model. It removes much of the ceremony of ASP.NET MVC by adopting a file-based routing approach. Each Razor Pages file found under the Pages directory equates to an endpoint.


1 Answers

How about:

@(Html.TextBoxFor<SomeModel>(i => i.Name))

Do parentheses help?

like image 78
Matt Hamilton Avatar answered Oct 21 '22 18:10

Matt Hamilton