Skip to content

Patch to implement Html.PartialAsync #9

Description

@kobruleht

Using @Html.PartialAsync in template causes error.

Add partial support using code like

  protected async Task<IHtmlstring> PartialAsync<T>(string viewName, T model)
        {
            // http://stackoverflow.com/questions/483091/render-a-view-as-a-string
            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 new Htmlstring  (sw.GetStringBuilder().ToString());
            }
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions