asp.net - Problem showing modelstate errors while using RenderPartialToString -


im using 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 partial view , form through json. works should, modelstate errors validationsummary not show. json return default form not highlight validation errors or show validation summary.

am missing something?

this how call renderpartialtostring:

string partialview = renderpartialtostring(this.controllercontext, "~/areas/user/views/account/changeaccountdetails.ascx", new viewdatadictionary(avd), new tempdatadictionary()); 

i had same issue similar code:

all fix when added lines:

// copy model state items html helper                 foreach (var item in context.controller.viewdata.modelstate)                     html.viewdata.modelstate.add(item); 

if port particular scenario ll like

    viewcontext viewcontext = new viewcontext(context, result.view, viewdata, tempdata, output);  //copy modelsate                 foreach (var item in context.controller.viewdata.modelstate)     viewcontext.controller.viewdata.modelstate.add(item);  result.view.render(viewcontext, output); 

Comments

Popular posts from this blog

Delphi Wmi Query on a Remote Machine -