How can i return Json Reslut + Web api + validate model + actionfilters +OnActionExecuting method

Topics: ASP.NET Web API
Nov 27, 2012 at 10:41 AM
Edited Nov 27, 2012 at 10:42 AM

string message = string.Empty;

public override void OnActionExecuting(HttpActionContext actionContext)

{

var modelState = actionContext.ModelState;

if (!modelState.IsValid)

actionContext.Response = actionContext.Request .CreateErrorResponse(HttpStatusCode.BadRequest, modelState);

foreach (var key in modelState.Keys)

{

var state = modelState[key];

if (state.Errors.Any())

 {

message = message + state.Errors.First().ErrorMessage;

}

}

}

 }

 

Here i want to return message variable with Jsonresult, please help me on it.