Reputation: 700
I've got a site build with RazorViewEngine where using "_ViewStart.cshtml" to set the layout to "Shared/_Layout.cshtml". Then, I've the following module:
public class LogModule : NancyModule
{
public LogModule()
{
Get["/log"] = _ =>
{
var list = GetLog().ToPagedList(1, 5);
return View["Index", list];
};
Get["/log/{page:int}"] = _ =>
{
int pageNumber = _.page ?? 1;
var list = GetLog().ToPagedList(pageNumber, 5);
return View["_List", list];
};
}
}
And the following views:
Index.cshtml
@using Nancy.ViewEngines.Razor
@using PagedList
@inherits NancyRazorViewBase<IPagedList<LogModel>>
<h1>View Log</h1>
<div id='container'>
@Html.Partial("_List", Model)
</div>
_List.cshtml
@using Nancy.ViewEngines.Razor
@using PagedList
@inherits NancyRazorViewBase<IPagedList<LogModel>>
<table class="table table-hover table-condensed">
<thead>
<tr>
<th>Date</th>
<th>Message</th>
</tr>
</thead>
<tbody>
@foreach (var log in Model)
{
<tr class="@log.Class">
<td>@log.Date</td>
<td>@log.Message</td>
</tr>
}
</tbody>
<tfoot>
<tr>
<td colspan="2">
<div class="pagination" data-current="@Model.PageNumber" data-count="@Model.PageCount">
<ul class="list-unstyled list-inline">
<li><a href="javascript:void(0)" class="pager first">|<</a></li>
<li><a href="javascript:void(0)" class="pager prev"><</a></li>
<li class="active"><span>@Model.PageNumber / @Model.PageCount</span></li>
<li><a href="javascript:void(0)" class="pager next">></a></li>
<li><a href="javascript:void(0)" class="pager last">>|</a></li>
</ul>
</div>
</td>
</tr>
</tfoot>
</table>
And finally, some javascript code to manage ajax requests to the '/log/{page:int}" action and replace the 'container' div with the result. Sadly, this result contains a full page, including _Layout.cshtml and breaking all the page.
In MVC this is solved using return PartialView(viewName, Model) but I couldn't find something similar in NancyFx. Is there something I'm missing?
Upvotes: 1
Views: 299
Reputation: 700
Turned out that the solution is quite simple. Just create an 'empty' layout file with this single line:
@RenderBody()
And then use it in your partial view:
@{ Layout = "Shared/_EmptyLayout"; }
Upvotes: 2