I tried the verification example code for web api in the latest mvc 4 download and I am getting some errors. Does anyone have an updated example of the ValidationActionFilter class.
Here is the source code
public class ValidationActionFilter : ActionFilterAttribute { public override void OnActionExecuting(HttpActionContext context) { var modelState = context.ModelState; if (!modelState.IsValid) { dynamic errors = new JsonObject(); foreach (var key in modelState.Keys) { var state = modelState[key]; if (state.Errors.Any()) { errors[key] = state.Errors.First().ErrorMessage; } } context.Response = new HttpResponseMessage<JsonValue>(errors, HttpStatusCode.BadRequest); } } }
I get an HttpResponseMessage error message
The non-generic type 'System.Net.Http.HttpResponseMessage' cannot be used with type arguments
It also looks like I need to add a Json link, but should I use JSON.net instead? An example of this using Json.net?
source share