Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi All
I need some help here.
I need to return a partial view as a string for JSON How would I go about this. Please note that my view inherits from a DynamicNode
Code:
public JsonResult HandleAddReview(ReviewModel Model) { DynamicNode dn = new DynamicNode(venuecontent.Id); return Json(new {val = PartialView("[Members]Reviews",dn)}); }
Hi Anton,
You have to do some method which will render Partial view in string.
return Json(new { htmlData = RenderRazorViewToString("partialView Path", model, ControllerContext, ViewData, TempData) }, JsonRequestBehavior.AllowGet); public static string RenderRazorViewToString(string viewName, object model, ControllerContext controllerContext, ViewDataDictionary viewData, TempDataDictionary tempData) { viewData.Model = model; using (var sw = new StringWriter()) { var viewResult = ViewEngines.Engines.FindPartialView(controllerContext, viewName); var viewContext = new ViewContext(controllerContext, viewResult.View, viewData, tempData, sw); viewResult.View.Render(viewContext, sw); viewResult.ViewEngine.ReleaseView(controllerContext, viewResult.View); return sw.GetStringBuilder().ToString(); } }
Thanks, Alex
Shot Alex.
That is exactly what I needed.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
6.1.5 Returning Partial View as string to JSON
Hi All
I need some help here.
I need to return a partial view as a string for JSON How would I go about this. Please note that my view inherits from a DynamicNode
Code:
Hi Anton,
You have to do some method which will render Partial view in string.
Thanks, Alex
Shot Alex.
That is exactly what I needed.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.