Problem showing modelstate errors while using RenderPartialToString

Posted by Martin on Stack Overflow See other posts from Stack Overflow or by Martin
Published on 2010-04-29T19:20:05Z Indexed on 2010/04/29 23:17 UTC
Read the original article Hit count: 665

Filed under:
|
|
|
|

Im using the following code:

public string RenderPartialToString(ControllerContext context, string partialViewName, ViewDataDictionary viewData, TempDataDictionary tempData)
    {
        ViewEngineResult result = ViewEngines.Engines.FindPartialView(context, partialViewName);

        if (result.View != null)
        {
            StringBuilder sb = new StringBuilder();
            using (StringWriter sw = new StringWriter(sb))
            {
                using (HtmlTextWriter output = new HtmlTextWriter(sw))
                {
                    ViewContext viewContext = new ViewContext(context, result.View, viewData, tempData, output);
                    result.View.Render(viewContext, output);
                }
            }

            return sb.ToString();
        }

        return String.Empty;
    }

To return a partial view and a form through JSON. It works as it should, but as soon as I get modelstate errors my ValidationSummary does not show. The JSON only return the default form but it does not highlight the validation errors or show the validation summary.

Am I missing something?

This is how I call the RenderPartialToString:

string partialView = RenderPartialToString(this.ControllerContext, "~/Areas/User/Views/Account/ChangeAccountDetails.ascx", new ViewDataDictionary(avd), new TempDataDictionary());

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp