ASP.NET MVC 3 and the @helper syntax within Razor

ASP.NET MVC 3 supports a new view-engine option called “Razor” (in addition to continuing to support/enhance the existing .aspx view engine).  Razor minimizes the number of characters and keystrokes required when writing a view template, and enables a fast, fluid coding workflow.

Unlike most template syntaxes, with Razor you do not need to interrupt your coding to explicitly denote the start and end of server blocks within your HTML. The Razor parser is smart enough to infer this from your code. This enables a compact and expressive syntax which is clean, fast and fun to type.

You can learn more about Razor from some of the blog posts I’ve done about it over the last last 9 months:

Today’s blog post covers a cool feature of Razor that a lot of people don’t know about – which is the ability to define re-usable helper methods using the @helper syntax.

Simple @helper method scenario

The @helper syntax within Razor enables you to easily create re-usable helper methods that can encapsulate output functionality within your view templates.  They enable better code reuse, and can also facilitate more readable code.  Let’s look at a super-simple scenario of how the @helper syntax can be used. 

Code before we define a @helper method

Let’s look at a simple product listing scenario where we list product details, and output either the price of the product – or the word “FREE!” if the item doesn’t cost anything:

image

The above code is fairly straight-forward, and Razor’s syntax makes it easy to integrate server-side C# code within the HTML. 

One place that is a little messy, though, is the if/else logic for the price.  We will likely output prices elsewhere within the site (or within the same page), and duplicating the above logic everywhere would be error-prone and hard to maintain.  Scenarios like this are prime candidates to extract and refactor into helper methods using the @helper syntax.

Refactoring the above sample using the @helper syntax

Let’s extract the price output logic, and encapsulate it within a helper method that we’ll name “DisplayPrice”.  We can do this by re-writing the sample to the code below:

image

We’ve used the @helper syntax above to define a reusable helper method named “DisplayPrice”.  Just like a standard C#/VB method, it can contain any number of arguments (you can also define the arguments to be either nullable or optional).  Unlike standard C#/VB methods, though, @helper methods can contain both content and code, and support the full Razor syntax within them – which makes it really easy to define and encapsulate rendering/formatting helper methods:

SNAGHTML20fae4df

You can invoke @helper methods just like you would a standard C# or VB method:

SNAGHTML20fcdc86

Visual Studio will provide code intellisense when invoking the method:

image

Reusing @helpers across multiple views

In the example above, we defined our @helper method within the same view template as the code that called it.  Alternatively, we can define the @helper method outside of our view template, and enable it to be re-used across all of the view templates in our project.

We can accomplish this by saving our @helper methods within .cshtml/.vbhtml files that are placed within a \App_Code directory that you create at the root of a project.  For example, below I created a “ScottGu.cshtml” file within the \App_Code folder, and defined two separate helper methods within the file (you can have any number of helper methods within each file):

SNAGHTML2107b6ae

Once our helpers are defined at the app level, we can use them within any view template of our application. 

The ScottGu.cshtml template in the \App_Code folder above will logically compile down to a class called “ScottGu” with static members of “DisplayPrice” and “AnotherHelper” within it.  We can re-write our previous sample to call it using the code below:

SNAGHTML210d65c1

Visual Studio will provide code intellisense when calling app-level helpers like this:

image

May 15th Update: One issue that a few people have pointed out is that when a @helper is saved within the \app_code directory, you don’t by default get access to the ASP.NET MVC Html helper methods within it (e.g. Html.ActionLink(), Html.TextBox(), etc).  You do get access to the built-in HTML helper methods when they are defined in the same file as your views.  This is not supported out of the box, though, when the helpers are within the \app_code directory - we’ll add this in the next release.  Paul Stovall has a nice helper class that you can use in the meantime to access and use the built-in Html helper methods within @helper methods you define in the \app_code directory.  You can learn how to use it here.

Summary

Razor’s @helper syntax provides a convenient way to encapsulate rendering functionality into helper methods that you can re-use within individual view templates, or across all view templates within a project. 

You can use this functionality to write code that is even cleaner and more maintainable. 

Hope this helps,

Scott

P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

Published Thursday, May 12, 2011 9:37 PM by ScottGu
Filed under: , , ,

Comments

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 12:49 AM by Hieu Pham

Very nice new help syntax. I love it, thanks Scottgu

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 12:51 AM by Jarord

Nice!  This will indeed be handy; didn't know it was coming.  How about a nice helper that transfers Razor (C#) value references to jQuery variables/prototypes?  Something like @jQVar?  Just reaching a little...

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 1:00 AM by Rafa Soares

I loved how you went from this:

public static class Helpers

{

public static MvsString MyField(this HtmlHelper helper, object value)

{

//(...)

}

}

to this:

@helper MyField(object value){

//(...)

}

Much cleaner syntax and intuitive usage.

Congrats and thank you!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 1:07 AM by Alex

There's always that bit of repetitive html/code that you're unsure if it should be an extension on HtmlHelper, or a PartialView. I think this fits beautifully in between those two for those kind of scenarios. Nice work.

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 1:14 AM by Alexander Bocharov

Thanks for the post! But i've got one question. Why do you back to the old App_Code instead of something like \Views\Helpers path? I think that using the path like \Views\Helpers should be more logic and pretty.

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 1:20 AM by ARGh!

Scott please blog when you will retire! You obviously forgot how to write code like the rest of folks at Microsoft. Serious it is time for you to go. hopefully soon the tablet and phone market will take off and Microsoft will be a distant memory like IBM. I can't wait.

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 1:22 AM by Parag Mehta

I got to admit, I didn't know about it. Nice post. This is kind of an alternative to partial views, so when to use Partial Views and when to use @helper? My guess is it's best to use Partial Views for stuffs that are shared across different views.

Internally what happens ? Does it create a static method? If so, how about the changes to it, do we need to "recompile" the app or it works just like partial views where we just change the syntax?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 2:05 AM by Mulle

Brilliant! ... Just brilliant!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 2:06 AM by Santosh

Cool Stuff! Nice addition!! MVC Rocks!!!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 2:12 AM by Gregor suttie

I didn't know about this until reading this article - Razor is indeed awesome.

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 2:22 AM by FlyingFishStix

Fantasic, that's very clear Scott!  I'm finally 'getting it' thanks to your nice posts.  

Cheers!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 2:37 AM by Chouteau

Very nice feature ! good job

How to write output cache directive with razor syntax on views like aspx or ascx <%@ OutputCache Duration="3600" VaryByParam="none" %> ?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 2:46 AM by ElmarG

Nice extension to the Razor syntax. Am I understanding correctly (seeing the intellisense) that these little helper methods can also be tested by a unit-test?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 3:07 AM by Mike

I'm a bit confused by the App_Code folder in WebApplication project though. Would this still work if compiling views is turned on in the project settings?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 4:03 AM by .fran

Great post, Scott, thanks! But, do you know, how fast is this solution, performancewise?

Is this method faster or slower when compared to regular HtmlHelper or Html.RenderAction methods?

Thanks in advance!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 4:05 AM by jarimba

Hi Scott,

What's the best way to reuse the helpers across multiple applications?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 4:12 AM by DalSoft

Great feature for simple helpers, but App_Code really? That's a bit webformish what's wrong with views/shared/helpers?  

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 4:43 AM by ldp615

Very nice! @helper method is awesome!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 5:57 AM by Marco Pietersma

hmmm is this the way to go ??

shall we put the code snippets of helpers in a code behind aka *.cshtml.cs

and maybe then we can put that code in a controler so that we have an MVC inject in MVC :D

no seriously, as long a developers only see this a hack in RAD projects it's fine. coz i get a little bit of classic asp flash back (old wine new bottles)

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 6:20 AM by Matt

Thanks for posting this - looks like a nice feature.

The App_Code folder seems like a silly location though - should be in the Views/Shared folder somewhere.

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 6:22 AM by Asyova

Where is the difference between App_Code and Shared under View folder?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 7:51 AM by Stephen

Is an "App_Code" folder really the best location for these kind of files. I guess its only semantics but shouldn't View Helpers be kept in the Views folder?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 9:12 AM by Matias

¡Excelent post!

Best regards from Argentina.

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 9:56 AM by Arian

Excellent code shortcut. Neat and powerfull

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 10:51 AM by tps

Scott, How would you handle this with a site with many many Areas?  I seem to remember trying this awhile back and having alot of trouble getting it to work.  Thanks.

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 12:48 PM by herry

Is it possible to use the helper across application domains?

I'd like to create a central helper repository that can be used by more than one ASP.NET MVC applications.

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 3:40 PM by thecapsaicinkid

@helpers always need the @ symbol, even when inside code blocks, right?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 4:42 PM by Dimskiy

Scott.  First of all, thanks for the post!

Now, I just upgraded a few of my old

public static MvcHtmlString MyHelper(this HtmlHelper helper...

to the new

@helper MyHelper(....

Looks great!  Works great!  The only things that I'm missing are the summaries for these functions.

My old helpers had summaries

/// <summary>Html Helper for such and such bla..</summary>

/// <param name="param1">The bla bla param</param>

/// <param name="param2">Param2, more bla...</param>

so that when developers are working with them, they get intellisense.

Is there any way to put summaries into @helpers?  If not, I would like to suggest implementing this functionality in the future.  Thank you!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 13, 2011 9:51 PM by LazyProgrammer

This looks like something that can easily become a pain if used more than sparingly. First I'll end up with a bloated cshtml file full of unrelated helper methods. Then I'll try to make separate cshtml files to organize my helper methods based on domain models. Then other developers will start duplicating business logic in there....Shouldn't something like this be in the View Model?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 5:02 AM by urenjoy

Really Very good and useful feature!!!

Thanks

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 9:35 AM by Webdiyer

Nice feature, thanks for the good job you've done!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 2:19 PM by Richard Moss

It looks like helpers can't be called recursively?

@helper ListCategories(Category parent)

{

 // Do some stuff

 foreach (Category item in Model.Where(c => c.ParentId == parentId))

 {

   <text>

   // Write some html

   </text>

   ListCategories(item);

 }

}

In the above example, only the initial call to ListCategories executes, the recursive calls seem to be completely ignored.

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 2:51 PM by Richard Moss

Disregard the above, I found that even though the intellisense lists the method inline in the helper without the @ prefix, it still needs to have this otherwise it doesn't execute. After adding the @ before the call, the recursion works fine.

Good job, saves having to write HtmlHelpers for no real reason :)

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 4:48 PM by ScottGu

@Jarod,

>>>>>>  How about a nice helper that transfers Razor (C#) value references to jQuery variables/prototypes?  Something like @jQVar?  Just reaching a little...

Good suggestion. We don't have something like that today - but we are always looking to add things in the future.

Thanks,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 4:50 PM by ScottGu

@Alexander,

>>>>>> Thanks for the post! But i've got one question. Why do you back to the old App_Code instead of something like \Views\Helpers path? I think that using the path like \Views\Helpers should be more logic and pretty.

It would have ideally been in a directory like that - but implementing that unfortunately would have taken a bit longer than we had.  The \App_Code approach works because of some existing infrastructure we already had in ASP.NET - and so we ended up going with that for the first release of Razor.  I'm hoping we'll be able to support more path locations in the future.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 4:51 PM by ScottGu

@Parag,

>>>>>>> Internally what happens ? Does it create a static method? If so, how about the changes to it, do we need to "recompile" the app or it works just like partial views where we just change the syntax?

Internally it compiles to a class with static methods.  ASP.NET automatically detect changes and will use them with the next request to the app.  So no need to explicitly recompile - this works just like with partial views.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 4:52 PM by ScottGu

@Paul,

>>>>>>> On MVC projects I had trouble making App_Code @helpers work with the MVC Html.ActionLink (etc.) helpers - my solution is linked below, but is there a better way?

Unfortunately that is a limitation in ASP.NET MVC 3 with the @helpers.  I will update the blog post to call that out.  We'll support the full MVC context in helpers with the next release.  The workaround you are using right now will help mitigate it.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 4:53 PM by ScottGu

@Chouteau

>>>>>>> How to write output cache directive with razor syntax on views like aspx or ascx <%@ OutputCache Duration="3600" VaryByParam="none" %> ?

I'd recommend using the Html.Action() helper method to achieve this.  I plan to do a blog post about this technique soon.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 4:54 PM by ScottGu

@ElmarG,

>>>>>>> Nice extension to the Razor syntax. Am I understanding correctly (seeing the intellisense) that these little helper methods can also be tested by a unit-test?

There isn't any direct support for unit testing these at the moment.  However, if you unit test your views you they can participate.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 4:56 PM by ScottGu

@Mike,

>>>>>>>> I'm a bit confused by the App_Code folder in WebApplication project though. Would this still work if compiling views is turned on in the project settings?

Conceptually you can think of the project compiling first - with all of the non-view code in the project being compiled into an assembly in the \bin directory.  ASP.NET at runtime then compiles the \App_Code folder and references all of the assemblies in the \bin folder.  View templates under the \Views folder are then compiled on demand and will reference both the \bin and \App_Code output.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 4:57 PM by ScottGu

@fran,

>>>>>>>> Great post, Scott, thanks! But, do you know, how fast is this solution, performancewise?  Is this method faster or slower when compared to regular HtmlHelper or Html.RenderAction methods?

This approach should be the same performance-wise as writing a custom HtmlHelper.  Both compile down to a class - and so the compiled code is equivalent at runtime.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 4:58 PM by ScottGu

@jarimba,

>>>>>> What's the best way to reuse the helpers across multiple applications?

Check out this cool tool to do that: razorgenerator.codeplex.com

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 4:59 PM by ScottGu

@DalSoft,

>>>>> Great feature for simple helpers, but App_Code really? That's a bit webformish what's wrong with views/shared/helpers?  

It would have ideally been in a directory like that - but implementing that unfortunately would have taken a bit longer than we had.  The \App_Code approach works because of some existing infrastructure we already had in ASP.NET - and so we ended up going with that for the first release of Razor.  I'm hoping we'll be able to support more path locations in the future.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 5:00 PM by ScottGu

@Matt,

>>>>>> Thanks for posting this - looks like a nice feature. The App_Code folder seems like a silly location though - should be in the Views/Shared folder somewhere.

It would have ideally been in a directory like that - but implementing that unfortunately would have taken a bit longer than we had.  The \App_Code approach works because of some existing infrastructure we already had in ASP.NET - and so we ended up going with that for the first release of Razor.  I'm hoping we'll be able to support more path locations in the future.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 5:02 PM by ScottGu

@smnbss,

>>>>>>> Have these problem being fixed in the release version?

Unfortunately that is a limitation in ASP.NET MVC 3 with the @helpers - it does not have built-in context of the MVC helpers.  I will update the blog post to call that out.  We'll support the full MVC context in helpers with the next release.  There is a helper workaround in that first StackOverflow post, though, that describes how to still get access to the MVC Context.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 5:04 PM by ScottGu

@stephen,

>>>>>>> Is an "App_Code" folder really the best location for these kind of files. I guess its only semantics but shouldn't View Helpers be kept in the Views folder?

It would have ideally been in a directory like \Views\Helpers - but implementing that unfortunately would have taken a bit longer than we had for the release.  The \App_Code approach works because of some existing infrastructure we already had in ASP.NET - and so we ended up going with that for the first release of Razor.  I'm hoping we'll be able to support more path locations in the future.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 5:05 PM by ScottGu

@tps,

>>>>>>> Scott, How would you handle this with a site with many many Areas?  I seem to remember trying this awhile back and having alot of trouble getting it to work.  Thanks.

I believe this will work from areas as long as the areas are in the same project.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 5:05 PM by ScottGu

@herry,

>>>>>>>> Is it possible to use the helper across application domains?  I'd like to create a central helper repository that can be used by more than one ASP.NET MVC applications.

This blog post describes how you could create a class library project of re-usable helpers: blogs.msdn.com/.../turn-your-razor-helpers-into-reusable-libraries.aspx

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 5:06 PM by ScottGu

@Dimskiy,

>>>>> Is there any way to put summaries into @helpers?  If not, I would like to suggest implementing this functionality in the future.  Thank you!

That is a good suggestion!  Unfortunately I don't know of a way to do this with the current release.  But it is a great suggestion for the future.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, May 14, 2011 5:08 PM by ScottGu

@LazyProgrammer,

>>>>>> Shouldn't something like this be in the View Model?

Not really.  Your view model classes should only contain the model information your view templates require - and shouldn't have any HTML generation logic within them.  The @helper methods above are really about HTML generation, and you can optionally pass them ViewModel data to work with.

Hope this helps,

Scott

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Sunday, May 15, 2011 12:23 PM by Justin Toth

Thanks for the article, this works great and lets me get rid of my custom FormatHelper class. The one thing that didn't work was adding a model reference at the top of the helper file, however referencing the function with the full namespace did work. For example:

@helper EncodeURL(string text)

{

   @Housters.Business.Utility.Helpers.URLHelper.Encode(text)

}

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Monday, May 16, 2011 12:32 PM by Asif Maniar

Very helpful as always. Thanks Scott!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Tuesday, May 17, 2011 2:29 AM by One thing I hate about Razor

There's something really smelly about Razor. Consider this:

<ul id="menu">

 <li>@Html.ActionLink("Home", "Index", "Home")</li>

 <li>@Html.ActionLink("About", "About", "Home")</li>

</ul>

The closing tag </li> is not required by the html standard. I should be able to leave it out if that is my choice. But if I do, the razor syntax will fail. I just think that stinks.

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Tuesday, May 17, 2011 3:39 AM by Lukas

Hi Scott,

is something similar planned for CSS? I.e. do you have something like 'LESS for ASP.net' in the pipeline?

Cheers, Lukas

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Tuesday, May 17, 2011 6:09 AM by Fun

This is great. Thanks for such helpful guide.

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Tuesday, May 17, 2011 7:00 AM by stej

Scott, thanks for the article. We tried the helpers but came to issues where generic helpers would help us.

Will Razor support generic helpers?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 20, 2011 8:04 AM by Connect

@LazyProgrammer said:

>> "Shouldn't something like this be in the View Model?"

@Scott replied:

>> "Not really.  Your view model classes should only contain the model information your view templates require - and shouldn't have any HTML generation logic within them.  The @helper methods above are really about HTML generation, and you can optionally pass them ViewModel data to work with."

I agree your model classes shouldn't contain HTML, but surely a flattened view model that exposes a string for DisplayPrice would be a better way of achieving this particular case? That way no logic is in the view at all, no need for masses of helpers and you can test your controller and get back the view model in unit tests?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Friday, May 20, 2011 2:54 PM by NNS76

Hi,

I think the logical place to put this code should be in the Model...

Why put it in the View?... i thought MVC was about abstraction......

Please explain....

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Thursday, May 26, 2011 11:45 PM by adycrystal

every one can post their owe information,why I can not???How can I post?Thanks!!!

You know,Christian Louboutin Shoes is very fashion,you can not miss it.In this Christian Louboutin Sales season, you deserve to have a pair of beautiful shoes with Christian Louboutin.  http://www.heelsvogue.com . kindly visite our website,thanks!!!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Wednesday, June 22, 2011 8:44 PM by Ethan Brown

Wow, this is incredibly @helpful (sorry, I couldn't resist myself).  Thanks for bringing this to my attention, Scott!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Saturday, June 25, 2011 3:22 AM by scarpe hogan

I like your post, hope you will share more with us,thanks!

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Monday, June 27, 2011 1:51 PM by Ken Smith

How can you use the various Html.XxxFor() methods within a helper? They take a generic argument (Expression<Func<TModel, TValue>> expression), and it doesn't seem possible to specify a generic argument into a helper method. Is that just a huge oversight on Microsoft's part, or was there some underlying conceptual reason that generic helpers aren't supported?

# re: ASP.NET MVC 3 and the @helper syntax within Razor

Thursday, July 7, 2011 2:56 AM by silvercrux

Love the @helper syntax. Thanks for this awesome post.