Articles : Page 1 of 1

  • Abstracting away issues of HttpContext from your ASP.NET MVC controllers

    Abstracting away issues of HttpContext from your ASP.NET MVC controllers

    Feb 12
    03

    I've noticed that I write software in one of three modes: For myself: Shortcuts, less testing, not well-factored. For myself but in public: Mostly POP Forums, which I try to avoid letting it suck since others will use it and see the code. For sharing: Any day job or gig where others will use or maintain your code. You don't want to unleash crapsauce on others. I have to admit that second case isn't the most clean of endeavors. While I'm generally happy with the forum app and the feedba...


  • How to access controller methods from a view in ASP.NET MVC

    How to access controller methods from a view in ASP.NET MVC

    Jul 11
    30

    This question has been posed in several places. One of the places is on StackOverflow here. The use case here is that my controller has important state or an important function, and I’d like to leverage it from the view. It’s not appropriate to factor out to an html helper or other view-based utility class. It is something unique to the controller. It would be very easy to just pass the controller over to the view so that the view could make use of its methods, but there is a lot of discussion...


  • 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...



  • 1