• MVC Razor Helpers using Delegates

    Published on MAR 9, 2012 about a 2 minute read

    Once in a while, I find myself implementing the same helper functions in different pages. In an effort to not repeat myself, I generally move helper functions into a common cshtml file in App_Code (as suggested here). While this works great for a single application, I’ve found myself copying helpers from project to project. So in order to avoid the copy-paste nightmare, I decided to see if I could abstract the basic functionality into an extension method and then have application specific rendering.

    .NET, MVC

  • Showing Enums as a Select List in MVC and Razor

    Published on JUL 27, 2011 about a 1 minute read

    Recently I needed to show a drop down list of all of the enumeration values. So I did what we all do and hit up Google. While there was plenty of information out there detailing how to convert the enum to a Dictionary<int, string> and render it, I couldn’t find something that fit my needs. Essentially I have an enumeration of field types. I wanted to display the names of those fields in a drop down list, but be able to make some of them prettier.

    .NET, MVC, RAZOR

  • Global Namespace Includes with MVC and Razor

    Published on MAR 7, 2011 about a 1 minute read

    While I’m loving MVC3 and the Razor view engine, I was sorely disappointed when I couldn’t use the system.web/pages/namespaces collection in web.config to add global namespace includes. After a bit of hunting and looking through the web.config files underneath the views folder (in each Area), I found that this can be accomplished by adding the following to the root web.config file: Now you can add any namespaces you require under the new razor namespaces section.

    .NET, MVC, RAZOR

home


Copyright © 2018 pseudomuto.com. All rights reserved.