Hi,
I have to render my partial view in html string (in controller), to return json object.
I found this function that works very well :
01.public static String RenderViewToString(ControllerContext context, String viewPath, object model = null)02. {03. context.Controller.ViewData.Model = model;04. using (var sw = new StringWriter())05. {06. //var viewResult = ViewEngines.Engines.FindView(context, viewPath, null);07. var viewResult = ViewEngines.Engines.FindPartialView(context, viewPath);08. var viewContext = new ViewContext(context, viewResult.View, context.Controller.ViewData, context.Controller.TempData, sw);09. viewResult.View.Render(viewContext, sw);10. viewResult.ViewEngine.ReleaseView(context, viewResult.View);11. return sw.GetStringBuilder().ToString();12. }13. }
With a kendo grid in partial view, i'm getting a "System.NullReferenceException" on the declaration @(Html.Kendo().Grid(.....
If I return the view with a "Return view" in my controller, it's ok.
My grid:
01.@(Html.Kendo().Grid((IEnumerable<MAGI.Model.DigicodeImmeuble>)mvDigicode)02. .Name("gridSyntheseDigicode")03. .HtmlAttributes(new { style = "width:100%;height: auto;", @class = "k-grid_encart k-grid_nopage" })04. .Columns(t =>05. {06. t.Bound(c => c.Digicode1.Nom).Title(tabTraduction[701972] + " 1");07. t.Bound(c => c.Digicode1.NoDigicode).Title(tabTraduction[100620]);08. t.Bound(c => c.Digicode2.Nom).Title(tabTraduction[701972] + " 2");09. t.Bound(c => c.Digicode2.NoDigicode).Title(tabTraduction[100620]);10. }11. )12. .Sortable()13. .Selectable()14. .DataSource(dataSource => dataSource15. .Ajax()16. .ServerOperation(false)17. )18. .Reorderable(reorder => reorder.Columns(true))19. .Events(events => events.DataBound("onDataBoundGridStandard"))20. )
mvDigicode and tabTraduction are not null.
That's work with the kendo chart module.
What's wrong with the grid ?
Many thanks,