I know that cshtml file gets complied into RazorPage, for example, I have a Products.cshtml file:
public class Views_Home_Products : RazorPage<dynamic>
{
public async override Task ExecuteAsync()
{
WriteLiteral("<!DOCTYPE html>\r\n<html>\r\n");
WriteLiteral("<head>");
WriteLiteral(@"<link href=""/lib/twitter-bootstrap/css/bootstrap.min.css"" rel=""stylesheet"" />");
WriteLiteral("</head>");
WriteLiteral("<body>");
// ...
WriteLiteral("<th>Name</th><td>");
Write(Model.Name);
// ...
}
// ...
}
but there is also a RazorView class (https://source.dot.net/#Microsoft.AspNetCore.Mvc.Razor/RazorView.cs)
public class RazorView : IView
{
private readonly IRazorViewEngine _viewEngine;
private readonly IRazorPageActivator _pageActivator;
private readonly HtmlEncoder _htmlEncoder;
// ...
public RazorView(IRazorViewEngine viewEngine,
IRazorPageActivator pageActivator,
IReadOnlyList<IRazorPage> viewStartPages,
IRazorPage razorPage
HtmlEncoder htmlEncoder,
DiagnosticListener diagnosticListener)
{
_viewEngine = viewEngine;
_pageActivator = pageActivator;
ViewStartPages = viewStartPages;
RazorPage = razorPage;
_htmlEncoder = htmlEncoder;
_diagnosticListener = diagnosticListener;
}
public string Path => RazorPage.Path;
public IRazorPage RazorPage { get; } // <--------------------- this is the compiled view file
public IReadOnlyList<IRazorPage> ViewStartPages { get; }
// ...
public virtual async Task RenderAsync(ViewContext context)
{
// eventually call RazorPage.ExecuteAsync();
}
}
So why we need to have a seperate IView class that wraps RazorPage?
IViewwhich is theVinMVC- Daniel A. White