Articles : Page 1 of 1

  • A Better Razor Foreach Loop

    A Better Razor Foreach Loop

    Apr 11
    14

    Yesterday, during my ASP.NET MVC 3 talk at Mix 11, I wrote a useful helper method demonstrating an advanced feature of Razor, Razor Templated Delegates. There are many situations where I want to quickly iterate through a bunch of items in a view, and I prefer using the foreach statement. But sometimes, I need to also know the current index. So I wrote an extension method to IEnumerable<T> that accepts Razor syntax as an argument and calls that template for each item in the enumeration. pub...


  • March 6th Links: ASP.NET, ASP.NET MVC, jQuery, EF, .NET

    March 6th Links: ASP.NET, ASP.NET MVC, jQuery, EF, .NET

    Mar 11
    07

    Here is the latest in my link-listing series. Also check out my Best of 2010 Summary for links to 100+ other posts I’ve done in the last year. [I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu] ASP.NET 35 ASP.NET and VS 2010 What’s New Videos: 35 free videos from Joe Stagner that highlight some of the new features that came in ASP.NET 4 and VS 2010. Filling in PDF Forms with ASP.NET and iTextSharp: Nice article by Scott Mitchell on ...


  • Defining Default Content For A Razor Layout Section

    Defining Default Content For A Razor Layout Section

    Mar 11
    05

    Layouts in Razor serve the same purpose as Master Pages do in Web Forms. They allow you to specify a layout for your site and carve out some placeholder sections for your views to implement. For example, here’s a simple layout with a main body section and a footer section. <!DOCTYPE html> <html> <head><title>Sample Layout</head> <body> <div>@RenderBody()</div> <footer>@RenderSection("Footer")</footer> </body> </html> In order to use this layout, your view might look like. @{ Layout ...


  • Templated Razor Delegates

    Templated Razor Delegates

    Feb 11
    27

    David Fowler turned me on to a really cool feature of Razor I hadn’t realized made it into 1.0, Templated Razor Delegates. What’s that? I’ll let the code do the speaking. @{ Func<dynamic, object> b = @<strong>@item</strong>; } <span>This sentence is b("In Bold").</span> That could come in handy if you have friends who’ll jump on your case for using the bold tag instead of the strong tag because it’s “not semantic”. Yeah, I’m looking at you Damian . I mean, don’t both words signify being ...



  • 1