Rename View() to Page()
This requires us to introduce another base class between RazorPageBase and Page - you need this because you aren't allow to have Page.Page().
This commit is contained in:
parent
490f94d425
commit
b1b3a816cc
|
|
@ -13,7 +13,7 @@ namespace MvcSandbox
|
||||||
public IActionResult OnPost(string name)
|
public IActionResult OnPost(string name)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
return View();
|
return Page();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes a Razor Page asynchronously.
|
/// Executes a Razor Page asynchronously.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Task ExecuteAsync(PageContext pageContext, PageViewResult result)
|
public virtual Task ExecuteAsync(PageContext pageContext, PageResult result)
|
||||||
{
|
{
|
||||||
if (result.Model != null)
|
if (result.Model != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -394,7 +394,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
|
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
result = new PageViewResult(_page);
|
result = new PageResult(_page);
|
||||||
}
|
}
|
||||||
|
|
||||||
await result.ExecuteResultAsync(_pageContext);
|
await result.ExecuteResultAsync(_pageContext);
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -56,11 +56,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the <see cref="RazorPages.Page"/> instance this model belongs to.
|
|
||||||
/// </summary>
|
|
||||||
public Page Page => PageContext?.Page;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="RazorPages.PageContext"/>.
|
/// Gets the <see cref="RazorPages.PageContext"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -798,6 +793,12 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
public virtual NotFoundObjectResult NotFound(object value)
|
public virtual NotFoundObjectResult NotFound(object value)
|
||||||
=> new NotFoundObjectResult(value);
|
=> new NotFoundObjectResult(value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="PageResult"/> object that renders the page.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="PageResult"/>.</returns>
|
||||||
|
public virtual PageResult Page() => new PageResult(PageContext.Page, this);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the file specified by <paramref name="physicalPath" /> (<see cref="StatusCodes.Status200OK"/>) with the
|
/// Returns the file specified by <paramref name="physicalPath" /> (<see cref="StatusCodes.Status200OK"/>) with the
|
||||||
/// specified <paramref name="contentType" /> as the Content-Type.
|
/// specified <paramref name="contentType" /> as the Content-Type.
|
||||||
|
|
@ -1546,15 +1547,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
public virtual UnauthorizedResult Unauthorized()
|
public virtual UnauthorizedResult Unauthorized()
|
||||||
=> new UnauthorizedResult();
|
=> new UnauthorizedResult();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a <see cref="PageViewResult"/> object that renders the page.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>The <see cref="PageViewResult"/>.</returns>
|
|
||||||
protected internal PageViewResult View()
|
|
||||||
{
|
|
||||||
return new PageViewResult(Page);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Validates the specified <paramref name="model"/> instance.
|
/// Validates the specified <paramref name="model"/> instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -11,23 +11,23 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An <see cref="ActionResult"/> that renders a Razor Page.
|
/// An <see cref="ActionResult"/> that renders a Razor Page.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PageViewResult : ActionResult
|
public class PageResult : ActionResult
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of <see cref="PageViewResult"/>.
|
/// Initializes a new instance of <see cref="PageResult"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="page">The <see cref="RazorPages.Page"/> to render.</param>
|
/// <param name="page">The <see cref="RazorPages.PageBase"/> to render.</param>
|
||||||
public PageViewResult(Page page)
|
public PageResult(PageBase page)
|
||||||
{
|
{
|
||||||
Page = page;
|
Page = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of <see cref="PageViewResult"/> with the specified <paramref name="model"/>.
|
/// Initializes a new instance of <see cref="PageResult"/> with the specified <paramref name="model"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="page">The <see cref="RazorPages.Page"/> to render.</param>
|
/// <param name="page">The <see cref="RazorPages.PageBase"/> to render.</param>
|
||||||
/// <param name="model">The page model.</param>
|
/// <param name="model">The page model.</param>
|
||||||
public PageViewResult(Page page, object model)
|
public PageResult(PageBase page, object model)
|
||||||
{
|
{
|
||||||
Page = page;
|
Page = page;
|
||||||
Model = model;
|
Model = model;
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="RazorPages.Page"/> to execute.
|
/// Gets the <see cref="RazorPages.Page"/> to execute.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Page Page { get; }
|
public PageBase Page { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the HTTP status code.
|
/// Gets or sets the HTTP status code.
|
||||||
|
|
@ -674,7 +674,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
_executeAction = executeAction;
|
_executeAction = executeAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task ExecuteAsync(PageContext pageContext, PageViewResult result)
|
public override Task ExecuteAsync(PageContext pageContext, PageResult result)
|
||||||
=> _executeAction(pageContext);
|
=> _executeAction(pageContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1422,7 +1422,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
Assert.Same(page, pageModel.Page);
|
|
||||||
Assert.Same(pageContext, pageModel.PageContext);
|
Assert.Same(pageContext, pageModel.PageContext);
|
||||||
Assert.Same(pageContext, pageModel.ViewContext);
|
Assert.Same(pageContext, pageModel.ViewContext);
|
||||||
Assert.Same(httpContext, pageModel.HttpContext);
|
Assert.Same(httpContext, pageModel.HttpContext);
|
||||||
|
|
@ -1491,10 +1490,10 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = pageModel.View();
|
var result = pageModel.Page();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var pageResult = Assert.IsType<PageViewResult>(result);
|
var pageResult = Assert.IsType<PageResult>(result);
|
||||||
Assert.Same(page, pageResult.Page);
|
Assert.Same(page, pageResult.Page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,14 @@
|
||||||
|
|
||||||
public IActionResult OnGet()
|
public IActionResult OnGet()
|
||||||
{
|
{
|
||||||
return View();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
public async Task<IActionResult> OnPostAsync()
|
||||||
{
|
{
|
||||||
await TaskCache.CompletedTask;
|
await TaskCache.CompletedTask;
|
||||||
MethodName = nameof(OnPostAsync);
|
MethodName = nameof(OnPostAsync);
|
||||||
return View();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnGetCustomer()
|
public async Task OnGetCustomer()
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,14 @@ namespace RazorPagesWebSite
|
||||||
|
|
||||||
public IActionResult OnGet()
|
public IActionResult OnGet()
|
||||||
{
|
{
|
||||||
return View();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
public async Task<IActionResult> OnPostAsync()
|
||||||
{
|
{
|
||||||
await TaskCache.CompletedTask;
|
await TaskCache.CompletedTask;
|
||||||
MethodName = nameof(OnPostAsync);
|
MethodName = nameof(OnPostAsync);
|
||||||
return View();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnGetCustomer()
|
public async Task OnGetCustomer()
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
{
|
{
|
||||||
Message = "From OnGet";
|
Message = "From OnGet";
|
||||||
|
|
||||||
return View();
|
return Page();
|
||||||
}
|
}
|
||||||
public string Message { get; set; } = "Default";
|
public string Message { get; set; } = "Default";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@
|
||||||
{
|
{
|
||||||
public IActionResult OnPostEdit(int id)
|
public IActionResult OnPostEdit(int id)
|
||||||
{
|
{
|
||||||
return View();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult OnPostDelete(int id)
|
public IActionResult OnPostDelete(int id)
|
||||||
{
|
{
|
||||||
return View();
|
return Page();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@ namespace RazorPagesWebSite.TempData
|
||||||
|
|
||||||
public IActionResult OnGet()
|
public IActionResult OnGet()
|
||||||
{
|
{
|
||||||
return View();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult OnPost()
|
public IActionResult OnPost()
|
||||||
{
|
{
|
||||||
Message = "Secret post";
|
Message = "Secret post";
|
||||||
return View();
|
return Page();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue