I have two files in my root directory namely “test1.cshtml” and “test2.cshtml”.
When I try to render test2.cshtml in test1.cshtml, it was successful, I used this code:
@RenderPage("~/test2.cshtml");
But when I try to render test2.cshtml in test1.cshtml using a code block, it wasn’t rendered.
@{
RenderPage("~/test2.cshtml");
}
Additional Information:
test2.cshtml contains this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
Hello WebMatrix
</body>
</html>
RenderPage returns a string
The @code syntax you used first is desigened to run a statement and write the output to the output stream
The second syntax you used just executes code; (its a code block like you pointed out, and it can contain multiple statements). You discard the result of the RenderPage statement that way!
try: