Nancy
Nancy copied to clipboard
Is there a way to render a Razor partial (without ViewStart) for an Ajax request?
Is there a way for the module or view to indicate that _ViewStart should not be loaded?
I see that there's a way to indicate that a page should be rendered as a partial by using HtmlHelper's Partial method, but that's for the use case where you want to inline HTML for reuse. However, I'm looking for a way for the module to indicate that no ViewStart should be used (similar to MVC's PartialViewResult).
Thanks!
@hoppersoft Did you find any solution to this problem?
I ended up modifying the Nancy/Nancy.ViewEngines.Razor code to get it working as it does in ASP.NET MVC. Thanks for reminding me; I’ve been meaning to submit a PR.
@hoppersoft Thanks for the prompt reply. It means, currently there is no way of doing this in nancy?
Nope; I had to resort to some fairly low-level hacking to make it work without breaking the existing SDHP. Once I get the PR in, you should be able to fork/patch/compile like we did.
I came up with this solution. This is my _ViewStart.cshtml
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase
@{
Layout = "Views/_SiteLayout.cshtml";
if ("XMLHttpRequest".Equals(
Request.Headers["x-requested-with"].FirstOrDefault(),
StringComparison.OrdinalIgnoreCase))
{
Layout = "Views/_Empty.cshtml";
}
ViewBag.Title = "Home";
}
and my _Empty.cshtml
@RenderSection("Styles", required: false)
@RenderBody()
@RenderSection("Scripts", required: false)