Using an EditorEntryFor helper makes the code DRYer and opens new possibilities, such as automatic indication of required fields. A small addition in one helper method will mark all required fields in entire MVC web application. It’s more or less standard to indicate required fields in a form with a red * next to the… Continue reading Automatic Marking of Required Fields with EditorEntryFor
Tag: Extension Methods
DRYing MVC Forms with an EditorEntryFor Helper
When creating forms in ASP.NET MVC I use a small helper to keep the code DRY (Don’t Repeat Yourself). The EditorEntryFor helper creates everything needed for a form field – the label, the input and the validation. When creating line of business applications, a huge part of the coding is often to create forms. Each… Continue reading DRYing MVC Forms with an EditorEntryFor Helper
Calling Non Public Setters
Properties with non public setters sometimes make sense – until a unit test requires an object to be set up in a specific state. I don’t want to make the setter public just because of the tests, so I wrote a small helper function that can call non public setters. The helper returns the object… Continue reading Calling Non Public Setters
Merging Expression Trees to Reuse in Linq Queries
Reusing parts of LINQ queries is easily done by chaining methods returning IQueryable. Unfortunately that doesn’t cover some senarios like reusing member initialization lists. To handle such a situation I wrote a Merge extension method for select expressions. For this post we’ll load the data required for a list of cars and a detail view… Continue reading Merging Expression Trees to Reuse in Linq Queries
Updating EntitySets with LINQ2SQL
This post is written by guest blogger Albin Sunnanbo. He’s a great friend and source of inspiration and also one of the best developers I know. It was Albin that first introduced me to LINQ, EF Migrations and jQuery that I now use daily. I often find myself in situations where I need to update… Continue reading Updating EntitySets with LINQ2SQL