2

Using Nancy and the Razor view engine I get the following situation. I have a view:

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        @Html.Partial("_PartialPage1")
    </body>
</html>

And a partial view containing:

   <strong>I am partial.</strong>

After running the application generated HTML looks like

<!DOCTYPE html>
<html>
    <head>
        <title></title>

    </head>
    <body>
        <div>
    <!DOCTYPE html>
<html>
    <head>
        <title></title>

    </head>
    <body>


<strong>I am partial.</strong>

</body>
</html>

</div>
    </body>
</html>

It seems as if the partial is rendered as a full HTML page instead of the snippet. Does anyone have an idea how to resolve this?

EDIT: I am using Nancy.Hosting.Aspnet.

UPDATE: I am using a _ViewStart.cshtml which seems to be applied to the partial view as well. Can this be prevented?

UPDATE: Files in the views folder

Views
  Default
    _ViewStart.cshtml
    Index.cshtml
  Partials
    _PartialPage.cshtml
  Shared
    _LayoutPage.cshtml

_ViewStart.cshtml contains the reference to the Layoutpage to be used.

@{
  Layout = "Views/Shared/_LayoutPage.cshtml";
}

The problem is that it is applied to the _PartialPage.cshtml as well. Independant of which folder the _ViewStart.cshtml is placed. I hope you can reproduce it like this.

Frank Witte
  • 466
  • 5
  • 17
  • I'm unable to reproduce this, but I'll be looking at upgrading Nancy to Razor 3.0 this weekend so will take another look. If you can create a reproducible project that would be awesome to help fix it. – Phill Nov 15 '13 at 16:46
  • Not sure how to upload a sample project. – Frank Witte Nov 19 '13 at 15:44
  • throw something up on Github, or dropbox, or pop into Jabbr Nancy room and I can give you my email. https://jabbr.net/#/rooms/nancyfx – Phill Nov 19 '13 at 16:05
  • A test project is available at: https://github.com/frankjwitte/NancyRazorPartial – Frank Witte Nov 20 '13 at 09:16
  • Awesome, thanks. I will pull it tonight and take a look. – Phill Nov 20 '13 at 10:06
  • I guess http://stackoverflow.com/questions/4081811/correct-way-to-use-viewstart-cshtml-and-partial-razor-views is a related question. Only, I do not see how the solution given there would be achieved with Nancy. – Frank Witte Nov 20 '13 at 10:54
  • looks like this is a bug, MVC seems to differ on the view returned but in Nancy we don't, so the magic of a Start View ends up being rendered all the time :( – Phill Nov 21 '13 at 15:22

1 Answers1

2

So in short, when using Nancy/Razor de _ViewStart.cshtml is applied to all views, even partial views. Thank you Phill for clearing that up.

Frank Witte
  • 466
  • 5
  • 17
  • I've fixed this, sending a PR in an hour or so, so hopefully will be in Nancy 0.22.0. Thanks for finding the issue. – Phill Nov 23 '13 at 13:24