Adam Schroder

Its Schotime.com!
FluentValidation Xval Integration

After a few months of using FluentValidation I asked its author Jeremy Skinner if it were possible to integrate this with xVal. At that time it was not possible because there were no easy way to access the properties needed by xVal. After submitting a few patches, we now have a solution which enables xVal integration with most of the FV validators.

Click here to find out more…

Cheers,

Adam

Integrating xVal Validation with Linq-to-Sql

In a previous post I showed you how you can use xVal and the IDataErrorInfo class to add validation to your Asp.net MVC website. In this post I will extend that to Linq-to-Sql and the classes it generates.

The northwind database has a suppliers table. The info contained below is using that table with linq-to-sql.

After adding the table to the designer, a Supplier class gets constructed in the background. This class is a partial class which means we can add to it without changing the code auto-generated in the designer.cs file.

Click here to keep reading…

Cheers,
Adam

Custom Validation Attributes

In my last post I showed you how to use Validation attributes on your model for validation. Today I will show how you can create your own attributes that can provide custom validation for you.

To accomplish this we need to inherit from ValidationAttribute. We'll create an attribute today that will only allow a "Yes" or "No" value to be entered. A pretty bad example however it will still suffice.

Click here to see the how its done.

Adam

Posted: Mar 10 2009, 09:12 PM by schotime | with no comments
Filed under: , , , ,
Validation with Asp.net MVC, xVal & IDataerrorInfo

I've been playing around with lots of different Validation concepts recently and I think I have come up with something that will be very useful. Hopefully you will also find it useful.

Firstly I have been looking at Steve Sanderson's new open source project xVal and decided that it was a good place to start. I was mainly looking at server side validation but xVal can also generate script to enable client side validation.

Firstly I'll show you how I integrated the DataAnnotations validation pack that Dynamic data uses and is available to us in 3.5sp1 as far as I know.


public class CustomValidation : IDataErrorInfo
{
    string IDataErrorInfo.Error
    {
        get
        {
            return string.Empty;
        }
    }

    string IDataErrorInfo.this[string columnName]
    {
        get
        {
            List<ErrorInfo> errors = 
                DataAnnotations.GetErrors(this, columnName).ToList();
            return errors.Count > 0 ? errors[0].ErrorMessage : null;
        }
    }
}

Sound interesting...? Click here to keep reading

Cheers,
Adam

Posted: Mar 05 2009, 09:50 PM by schotime | with 2 comment(s)
Filed under: , , ,
Custom Authorization With Asp.net MVC

The whole advantage with MVC over webforms is extensibility at every point. Extensibility, Extensibility, Extensibility.

Authorization is a very important and every web project has there own needs and requirements. Full customisation is paramount.

Here I will show you a simple way to customise your authorization.

In MVC attributes are used to protect a controller method, so we to get started all we need to do is inherit from the AuthorizeAttribute class.

Click here to see the solution

Happy Coding

Adam

Posted: Feb 17 2009, 09:27 PM by schotime | with no comments
Filed under: , ,
Retrieving Data Without the Dataset With Custom SQL

In my previous post I used custom sql query and transformed the results into a nested class. However you may have overlooked way I got the data into a class. It quite easy and will work with all database connectors that implement IDbConnection.

Here is how its done. We use the DataContext that came with and used by Linq2Sql.

Click here to see the solution.

Adam

Posted: Feb 12 2009, 08:47 PM by schotime | with no comments
Filed under: , ,
Transforming one-to-many Sql into Nested Class

Back in the days of Classic ASP, when you had a one too many relationship displaying the data was pretty painful. You would do things like


var reference_number_old =
"$##%@"; while (recordsExist) { reference_number = String(rs(0)); if (reference_number_old != reference_number) { Response.Write(reference_number); reference_number_old = reference_number; } //Do more stuff }

Sooo very very painful, and that's only grouping by one column (reference number).

Now however with OO programming and the advance of Linq there is a much nicer and easier way to deal with this Master-Detail type one-to-many relationship.

Lets see how we do it now, still using our own custom sql.

Click Here to Keep Reading...

Cheers
Schotime

 

 

 

Posted: Jan 22 2009, 09:23 PM by schotime | with no comments
Filed under:
Running ASP.NET MVC Applications Under IIS6

Yes...Finally...I have full control of my HTML again, but am still able to work with a great language like C#. MVC is here and its great. I'm absolutely loving it. But how the heck do you get it to work under IIS6. What if I want extensionless URL's? Here is a few options for you.

Click Here to read on.....

Schotime

Returning a Dataset, Datatable in Json

After my previous posts about returning data in JSON, I decided to have a go at returning a generic Datatable. This however is not as easy as simple returning a Datatable in your code behind method or web service. There a solution though and here it is.

If you break a Datatable down it is really only a List of Dictionary objects so that's how we'll approach this problem. This is compatible with .NET 2.0 and above, with the Ajax installed.

I'd like to acknowledge RichardD for the idea.

Click here to view the simple solution.

jQuery Plugin for ASP.net Ajax (jMsAjax)

After my recent post on jQuery, JSON and dates in asp.net I decided that there must be a better solution so I set out writing my first jQuery plugin. And after a few hours I had it working to my delight.

It not only accepts a raw JSON object as input for method parameters, but safely parses and stringify's the object using Crockford's implementation (http://www.json.org/js.html). The syntax of the call doesn't change if it is a "POST" or a "GET" as it is all handled inside the plugin. It also returns Dates without a problem.

Click here to keep reading....

Schotime

More Posts Next page »