Thursday, 27 December 2012

Creating Custom RemoteAttributes to ensure IsValid() calls the correct validation method

In a previous post i noted that the IsValid() method of the System.Web.Mvc.RemoteAttribute class simply returns true.

It makes much more sense to have the IsValid() method actually invoke the method specified in the 'HttpMethod' property i.e. the method configured to be called from the client to perform the remote validation...however, by calling it within IsValid(), then the validation routine will be performed on the server as part of the default model binding.

The objective is to be able to simply check ModelState.IsValid() within a Controller Action and know that whatever validation method you specify in the RemoteAttribute declaration is called.

The code for the custom remote attribute:

Temp Link to another solution

No comments:

Post a Comment