Skip to content

Commit

Permalink
Partial method in HtmlHelpers updated to fix a problem with @Html.Par…
Browse files Browse the repository at this point in the history
…tial statement in Razor view
  • Loading branch information
rspacjer committed Oct 3, 2011
1 parent dfc2af2 commit 5f52736
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/Nancy.ViewEngines.Razor.Tests/RazorViewCompilerFixture.cs
Expand Up @@ -49,5 +49,35 @@ public void GetCompiledView_should_render_to_stream()
// Then
stream.ShouldEqual("<h1>Hello Mr. test</h1>");
}

[Fact]
public void Should_be_able_to_render_view_with_partial_to_stream()
{
// Given
var location = new ViewLocationResult(
string.Empty,
string.Empty,
"cshtml",
() => new StringReader(@"@{var x = ""test"";}<h1>Hello Mr. @x</h1> @Html.Partial(""partial.cshtml"")")
);

var partialLocation = new ViewLocationResult(
string.Empty,
"partial.cshtml",
"cshtml",
() => new StringReader(@"this is partial")
);

A.CallTo(() => this.renderContext.LocateView("partial.cshtml",null)).Returns(partialLocation);

var stream = new MemoryStream();

// When
var response = this.engine.RenderView(location, null,this.renderContext);
response.Contents.Invoke(stream);

// Then
stream.ShouldEqual("<h1>Hello Mr. test</h1> this is partial");
}
}
}
3 changes: 2 additions & 1 deletion src/Nancy.ViewEngines.Razor/HtmlHelpers.cs
Expand Up @@ -29,7 +29,8 @@ public IHtmlString Partial(string viewName, dynamic model)
{
ViewLocationResult view = this.renderContext.LocateView(viewName, model);

Action<Stream> action = this.engine.RenderView(view, model, this.renderContext);
Response response = this.engine.RenderView(view, model, this.renderContext);
Action<Stream> action = response.Contents;
var mem = new MemoryStream();

action.Invoke(mem);
Expand Down

0 comments on commit 5f52736

Please sign in to comment.