Showing posts with label aspnet. Show all posts
Showing posts with label aspnet. Show all posts

Tuesday, August 27, 2013

Binding enum arrays with MVC models

The simplicity of model binding in the MVC framework makes it a powerful and pleasant framework to send models up and down to views. But a little short coming prevents the usage of enum arrays and raising maintainability in my opinion. MVC 4 cannot convert / materialize enum values to an array when used in a model. To put it correctly, there is no standard type converter for the job.

This issue manifested when I was working on a checkbox list of statuses that could be selected as a filter. This would then be posted as a comma separated parameter value to be set on the model object. Which is finally used in a LINQ query.

Monday, April 8, 2013

Improved compiletime supported validators

After a the initial post on the compile-time supporting webform validators, a few itches started to surface. Mainly the extendability and cleanliness. With some slight changes it was possible to categorize the validators (thus enforcing more of the Single Responsibility Principle).

Usage


The following code demonstrates the usage of this API. Note that there are breaking changes if you are replacing the previous version.
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    this.UsernameField.Validation().RequiredField("username");
    this.PasswordField.Validation().RequiredField("password");
}
Read the original post for implementation details.

Thursday, January 6, 2011

ASP.NET Compile Time Supported Validators

UPDATED VERSION

Click here for the latest blog.

With.NET 3.5 extension methods were introduced, these methods provide a great way built features into 'closed' objects or doing a way of IOC.

Either way, the following example shows the usages a 'simple' validation framework. It provides extensions to validate web controls with compile time support. Which is quiet nice if don't have to write any markup code anymore.

Wednesday, November 10, 2010

Creating compile time supported URLs

COVERAGE: ASP.Net C#, Microsoft AntiXss, LINQ, CuttingEdge Conditions.

When it comes to ASP.Net and linking to other pages it's a very lose system. Which is strange when you think about it. We're working in assemblies here, pages are classes and classes can have 'relations' with other classes and be supported by the compiler. Yet there are a lot of NavigateUrl's being filled with strings from either code or markup. Brrr.