I've got a class which extends PartialViewResult
and in this class I'm setting the Response.StatusCode
and the Model via ViewData
.
My model and statuscode are getting set as I'd expect, but my model isn't validated. Are their additional steps needed to ensure my model is validated? It feels like I've hooked into the wrong place (as in too late) in the pipeline and the model should already be validated before passing it to result but I'm not 100%.
Here's the class:
public class PartialViewResultWithErrorCode<T> : PartialViewResult where T : class
{
private readonly HttpStatusCode statusCode;
private readonly T model;
public PartialViewResultWithErrorCode(HttpStatusCode statusCode, string viewName, T model)
{
this.statusCode = statusCode;
this.model = model;
ViewName = viewName;
}
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.StatusCode = (int)statusCode;
ViewData = new ViewDataDictionary(model);
base.ExecuteResult(context);
}
}
Any thoughts greatly appreciated.