Bhupinder Singh
Bhupinder Singh

Reputation: 39

RenderPartial method in Razor view

I know that in razor syntax we have to keep the RenderPartial method inside the curly braces. Also, that it returns void and is written directly to the output stream.

eg.- @{ Html.RenderPartial("Category","Home"); }

Now, I have two questions 1. What is an output stream 2. What is the significance of the curly braces?

Upvotes: 1

Views: 184

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239240

The curly brace syntax just means that some C#/VB code exists there. It informs Razor to parse everything within as straight code.

Now, saying it gets written directly to the output stream is a bit simplistic. Essentially, in building a response for the server to send to the client, the response body is a stream. The "output stream" is essentially the same thing as the "response body". When Razor parse a view, it begins writing to that response body, and essentially Html.RenderPartial writes directly to the response body, as well, rather than returning something to Razor which Razor would then write to the response body.

That said, just use Html.Partial unless you have a good reason otherwise:

@Html.Partial("Category", "Home")

Upvotes: 2

Related Questions