-
-
Save rytmis/998898 to your computer and use it in GitHub Desktop.
Razor weirdness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Create</h2> | |
@using(Html.BeginForm()){ | |
@Html.Partial("form"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Create</h2> | |
@using(Html.BeginForm()){ | |
Html.RenderPartial("form"); | |
} |
It works.. Thanks a lot!
I figured something like that.. But I didn't assume that razor would pick up on a simple Html.RenderPartial call within my markup .. I fully expected @ to simply start a code block..
Thanks..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The trick is: RenderPartial returns void, so it's not an expression, it's a statement. Once you're already inside a Razor code block, you don't use the @{ } syntax for statements. OTOH, Partial is an expression (it returns the content), so once you're inside a code block, you use @ to denote that it's an expression to be output. It would compile without the @ as well, but then the result wouldn't be output. :-)