Make Partial on PageBase and PageModel work correctly (#13013)

* Make Partial on PageBase and PageModel work correctly

Fixes https://github.com/aspnet/AspNetCore/issues/10438
This commit is contained in:
Pranav K 2019-08-13 12:49:10 -07:00 committed by GitHub
parent c80f7d1dd9
commit 9bd027aa99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 212 additions and 148 deletions

View File

@ -368,6 +368,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
{
protected PageBase() { }
public Microsoft.AspNetCore.Http.HttpContext HttpContext { get { throw null; } }
public Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider MetadataProvider { get { throw null; } set { } }
public Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary ModelState { get { throw null; } }
public Microsoft.AspNetCore.Mvc.RazorPages.PageContext PageContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
public Microsoft.AspNetCore.Http.HttpRequest Request { get { throw null; } }
@ -500,6 +501,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
{
protected PageModel() { }
public Microsoft.AspNetCore.Http.HttpContext HttpContext { get { throw null; } }
public Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider MetadataProvider { get { throw null; } set { } }
public Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary ModelState { get { throw null; } }
[Microsoft.AspNetCore.Mvc.RazorPages.PageContextAttribute]
public Microsoft.AspNetCore.Mvc.RazorPages.PageContext PageContext { get { throw null; } set { } }

View File

@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Net.Http.Headers;
@ -61,6 +62,19 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// </summary>
public ModelStateDictionary ModelState => PageContext?.ModelState;
/// <summary>
/// Gets or sets the <see cref="IModelMetadataProvider"/>.
/// </summary>
public IModelMetadataProvider MetadataProvider
{
get
{
_metadataProvider ??= HttpContext?.RequestServices?.GetRequiredService<IModelMetadataProvider>();
return _metadataProvider;
}
set => _metadataProvider = value ?? throw new ArgumentNullException(nameof(value));
}
private IObjectModelValidator ObjectValidator
{
get
@ -74,19 +88,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
}
private IModelMetadataProvider MetadataProvider
{
get
{
if (_metadataProvider == null)
{
_metadataProvider = HttpContext?.RequestServices?.GetRequiredService<IModelMetadataProvider>();
}
return _metadataProvider;
}
}
private IModelBinderFactory ModelBinderFactory
{
get
@ -216,7 +217,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> Content(content, (MediaTypeHeaderValue)null);
/// <summary>
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// <paramref name="content"/> string and a content type.
/// </summary>
/// <param name="content">The content to write to the response.</param>
@ -226,7 +227,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> Content(content, MediaTypeHeaderValue.Parse(contentType));
/// <summary>
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// <paramref name="content"/> string, a <paramref name="contentType"/>, and <paramref name="contentEncoding"/>.
/// </summary>
/// <param name="content">The content to write to the response.</param>
@ -245,7 +246,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// <paramref name="content"/> string and a <paramref name="contentType"/>.
/// </summary>
/// <param name="content">The content to write to the response.</param>
@ -292,14 +293,14 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// challenge.</param>
/// <returns>The created <see cref="ForbidResult"/> for the response.</returns>
/// <remarks>
/// Some authentication schemes, such as cookies, will convert <see cref="StatusCodes.Status403Forbidden"/> to
/// Some authentication schemes, such as cookies, will convert <see cref="StatusCodes.Status403Forbidden"/> to
/// a redirect to show a login page.
/// </remarks>
public virtual ForbidResult Forbid(AuthenticationProperties properties)
=> new ForbidResult(properties);
/// <summary>
/// Creates a <see cref="ForbidResult"/> (<see cref="StatusCodes.Status403Forbidden"/> by default) with the
/// Creates a <see cref="ForbidResult"/> (<see cref="StatusCodes.Status403Forbidden"/> by default) with the
/// specified authentication schemes and <paramref name="properties" />.
/// </summary>
/// <param name="properties"><see cref="AuthenticationProperties"/> used to perform the authentication
@ -405,7 +406,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> new PhysicalFileResult(physicalPath, contentType) { FileDownloadName = fileDownloadName };
/// <summary>
/// Creates a <see cref="LocalRedirectResult"/> object that redirects
/// Creates a <see cref="LocalRedirectResult"/> object that redirects
/// (<see cref="StatusCodes.Status302Found"/>) to the specified local <paramref name="localUrl"/>.
/// </summary>
/// <param name="localUrl">The local URL to redirect to.</param>
@ -438,7 +439,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <summary>
/// Creates a <see cref="LocalRedirectResult"/> object with <see cref="LocalRedirectResult.Permanent"/> set to
/// false and <see cref="LocalRedirectResult.PreserveMethod"/> set to true
/// false and <see cref="LocalRedirectResult.PreserveMethod"/> set to true
/// (<see cref="StatusCodes.Status307TemporaryRedirect"/>) using the specified <paramref name="localUrl"/>.
/// </summary>
/// <param name="localUrl">The local URL to redirect to.</param>
@ -455,7 +456,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <summary>
/// Creates a <see cref="LocalRedirectResult"/> object with <see cref="LocalRedirectResult.Permanent"/> set to
/// true and <see cref="LocalRedirectResult.PreserveMethod"/> set to true
/// true and <see cref="LocalRedirectResult.PreserveMethod"/> set to true
/// (<see cref="StatusCodes.Status308PermanentRedirect"/>) using the specified <paramref name="localUrl"/>.
/// </summary>
/// <param name="localUrl">The local URL to redirect to.</param>
@ -527,7 +528,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <summary>
/// Creates a <see cref="RedirectResult"/> object with <see cref="RedirectResult.Permanent"/> set to false
/// and <see cref="RedirectResult.PreserveMethod"/> set to true (<see cref="StatusCodes.Status307TemporaryRedirect"/>)
/// and <see cref="RedirectResult.PreserveMethod"/> set to true (<see cref="StatusCodes.Status307TemporaryRedirect"/>)
/// using the specified <paramref name="url"/>.
/// </summary>
/// <param name="url">The URL to redirect to.</param>
@ -544,7 +545,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <summary>
/// Creates a <see cref="RedirectResult"/> object with <see cref="RedirectResult.Permanent"/> set to true
/// and <see cref="RedirectResult.PreserveMethod"/> set to true (<see cref="StatusCodes.Status308PermanentRedirect"/>)
/// and <see cref="RedirectResult.PreserveMethod"/> set to true (<see cref="StatusCodes.Status308PermanentRedirect"/>)
/// using the specified <paramref name="url"/>.
/// </summary>
/// <param name="url">The URL to redirect to.</param>
@ -568,7 +569,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> RedirectToAction(actionName, routeValues: null);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status302Found"/>) to the specified action using the
/// Redirects (<see cref="StatusCodes.Status302Found"/>) to the specified action using the
/// <paramref name="actionName"/> and <paramref name="routeValues"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
@ -578,7 +579,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> RedirectToAction(actionName, controllerName: null, routeValues: routeValues);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status302Found"/>) to the specified action using the
/// Redirects (<see cref="StatusCodes.Status302Found"/>) to the specified action using the
/// <paramref name="actionName"/> and the <paramref name="controllerName"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
@ -632,15 +633,15 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> new RedirectToActionResult(actionName, controllerName, routeValues, fragment);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to false and <see cref="RedirectToActionResult.PreserveMethod"/>
/// set to true, using the specified <paramref name="actionName"/>, <paramref name="controllerName"/>,
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to false and <see cref="RedirectToActionResult.PreserveMethod"/>
/// set to true, using the specified <paramref name="actionName"/>, <paramref name="controllerName"/>,
/// <paramref name="routeValues"/>, and <paramref name="fragment"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
/// <param name="controllerName">The name of the controller.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
public virtual RedirectToActionResult RedirectToActionPreserveMethod(
string actionName = null,
@ -658,7 +659,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
@ -669,8 +670,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>
/// and <paramref name="routeValues"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
@ -682,8 +683,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>
/// and <paramref name="controllerName"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
@ -695,7 +696,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>,
/// <paramref name="controllerName"/>, and <paramref name="fragment"/>.
/// </summary>
@ -712,7 +713,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>,
/// <paramref name="controllerName"/>, and <paramref name="routeValues"/>.
/// </summary>
@ -729,7 +730,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>,
/// <paramref name="controllerName"/>, <paramref name="routeValues"/>, and <paramref name="fragment"/>.
/// </summary>
@ -753,16 +754,16 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status308PermanentRedirect"/>) to the specified action with
/// Redirects (<see cref="StatusCodes.Status308PermanentRedirect"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true and <see cref="RedirectToActionResult.PreserveMethod"/>
/// set to true, using the specified <paramref name="actionName"/>, <paramref name="controllerName"/>,
/// set to true, using the specified <paramref name="actionName"/>, <paramref name="controllerName"/>,
/// <paramref name="routeValues"/>, and <paramref name="fragment"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
/// <param name="controllerName">The name of the controller.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
public virtual RedirectToActionResult RedirectToActionPermanentPreserveMethod(
string actionName = null,
string controllerName = null,
@ -839,14 +840,14 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified route with
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified route with
/// <see cref="RedirectToRouteResult.Permanent"/> set to false and <see cref="RedirectToRouteResult.PreserveMethod"/>
/// set to true, using the specified <paramref name="routeName"/>, <paramref name="routeValues"/>, and <paramref name="fragment"/>.
/// </summary>
/// <param name="routeName">The name of the route.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
public virtual RedirectToRouteResult RedirectToRoutePreserveMethod(
string routeName = null,
object routeValues = null,
@ -861,7 +862,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// <see cref="RedirectToRouteResult.Permanent"/> set to true using the specified <paramref name="routeName"/>.
/// </summary>
/// <param name="routeName">The name of the route.</param>
@ -872,7 +873,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// <see cref="RedirectToRouteResult.Permanent"/> set to true using the specified <paramref name="routeValues"/>.
/// </summary>
/// <param name="routeValues">The parameters for a route.</param>
@ -896,7 +897,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// <see cref="RedirectToRouteResult.Permanent"/> set to true using the specified <paramref name="routeName"/>
/// and <paramref name="fragment"/>.
/// </summary>
@ -931,7 +932,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <param name="routeName">The name of the route.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
public virtual RedirectToRouteResult RedirectToRoutePermanentPreserveMethod(
string routeName = null,
object routeValues = null,
@ -1074,7 +1075,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> new RedirectToPageResult(pageName, pageHandler, routeValues, permanent: true, fragment: fragment);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified page with
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified page with
/// <see cref="RedirectToRouteResult.Permanent"/> set to false and <see cref="RedirectToRouteResult.PreserveMethod"/>
/// set to true, using the specified <paramref name="pageName"/>, <paramref name="routeValues"/>, and <paramref name="fragment"/>.
/// </summary>
@ -1082,7 +1083,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <param name="pageHandler">The page handler to redirect to.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
public virtual RedirectToPageResult RedirectToPagePreserveMethod(
string pageName = null,
string pageHandler = null,
@ -1107,7 +1108,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <param name="pageHandler">The page handler to redirect to.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
public virtual RedirectToPageResult RedirectToPagePermanentPreserveMethod(
string pageName = null,
string pageHandler = null,
@ -1206,12 +1207,17 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <returns>The created <see cref="PartialViewResult"/> object for the response.</returns>
public virtual PartialViewResult Partial(string viewName, object model)
{
ViewContext.ViewData.Model = model;
// ViewContext.ViewData is an instance of ViewDataDictionary<MyPageModel>, but we need an instance
// of ViewDataDictionary<MyPartialViewModel>.
var viewData = new ViewDataDictionary(MetadataProvider, ViewContext.ViewData.ModelState)
{
Model = model,
};
return new PartialViewResult
{
ViewName = viewName,
ViewData = ViewContext.ViewData
ViewData = viewData
};
}

View File

@ -139,6 +139,19 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
}
/// <summary>
/// Gets or sets the <see cref="IModelMetadataProvider"/>.
/// </summary>
public IModelMetadataProvider MetadataProvider
{
get
{
_metadataProvider ??= HttpContext?.RequestServices?.GetRequiredService<IModelMetadataProvider>();
return _metadataProvider;
}
set => _metadataProvider = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Gets the <see cref="ViewDataDictionary"/>.
/// </summary>
@ -157,19 +170,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
}
private IModelMetadataProvider MetadataProvider
{
get
{
if (_metadataProvider == null)
{
_metadataProvider = HttpContext?.RequestServices?.GetRequiredService<IModelMetadataProvider>();
}
return _metadataProvider;
}
}
private IModelBinderFactory ModelBinderFactory
{
get
@ -616,7 +616,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> Content(content, (MediaTypeHeaderValue)null);
/// <summary>
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// <paramref name="content"/> string and a content type.
/// </summary>
/// <param name="content">The content to write to the response.</param>
@ -626,7 +626,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> Content(content, MediaTypeHeaderValue.Parse(contentType));
/// <summary>
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// <paramref name="content"/> string, a <paramref name="contentType"/>, and <paramref name="contentEncoding"/>.
/// </summary>
/// <param name="content">The content to write to the response.</param>
@ -645,7 +645,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// Creates a <see cref="ContentResult"/> object with <see cref="StatusCodes.Status200OK"/> by specifying a
/// <paramref name="content"/> string and a <paramref name="contentType"/>.
/// </summary>
/// <param name="content">The content to write to the response.</param>
@ -692,14 +692,14 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// challenge.</param>
/// <returns>The created <see cref="ForbidResult"/> for the response.</returns>
/// <remarks>
/// Some authentication schemes, such as cookies, will convert <see cref="StatusCodes.Status403Forbidden"/> to
/// Some authentication schemes, such as cookies, will convert <see cref="StatusCodes.Status403Forbidden"/> to
/// a redirect to show a login page.
/// </remarks>
public virtual ForbidResult Forbid(AuthenticationProperties properties)
=> new ForbidResult(properties);
/// <summary>
/// Creates a <see cref="ForbidResult"/> (<see cref="StatusCodes.Status403Forbidden"/> by default) with the
/// Creates a <see cref="ForbidResult"/> (<see cref="StatusCodes.Status403Forbidden"/> by default) with the
/// specified authentication schemes and <paramref name="properties" />.
/// </summary>
/// <param name="properties"><see cref="AuthenticationProperties"/> used to perform the authentication
@ -780,7 +780,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> new VirtualFileResult(virtualPath, contentType) { FileDownloadName = fileDownloadName };
/// <summary>
/// Creates a <see cref="LocalRedirectResult"/> object that redirects
/// Creates a <see cref="LocalRedirectResult"/> object that redirects
/// (<see cref="StatusCodes.Status302Found"/>) to the specified local <paramref name="localUrl"/>.
/// </summary>
/// <param name="localUrl">The local URL to redirect to.</param>
@ -813,7 +813,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <summary>
/// Creates a <see cref="LocalRedirectResult"/> object with <see cref="LocalRedirectResult.Permanent"/> set to
/// false and <see cref="LocalRedirectResult.PreserveMethod"/> set to true
/// false and <see cref="LocalRedirectResult.PreserveMethod"/> set to true
/// (<see cref="StatusCodes.Status307TemporaryRedirect"/>) using the specified <paramref name="localUrl"/>.
/// </summary>
/// <param name="localUrl">The local URL to redirect to.</param>
@ -830,7 +830,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <summary>
/// Creates a <see cref="LocalRedirectResult"/> object with <see cref="LocalRedirectResult.Permanent"/> set to
/// true and <see cref="LocalRedirectResult.PreserveMethod"/> set to true
/// true and <see cref="LocalRedirectResult.PreserveMethod"/> set to true
/// (<see cref="StatusCodes.Status308PermanentRedirect"/>) using the specified <paramref name="localUrl"/>.
/// </summary>
/// <param name="localUrl">The local URL to redirect to.</param>
@ -924,7 +924,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <summary>
/// Creates a <see cref="RedirectResult"/> object with <see cref="RedirectResult.Permanent"/> set to false
/// and <see cref="RedirectResult.PreserveMethod"/> set to true (<see cref="StatusCodes.Status307TemporaryRedirect"/>)
/// and <see cref="RedirectResult.PreserveMethod"/> set to true (<see cref="StatusCodes.Status307TemporaryRedirect"/>)
/// using the specified <paramref name="url"/>.
/// </summary>
/// <param name="url">The URL to redirect to.</param>
@ -941,7 +941,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <summary>
/// Creates a <see cref="RedirectResult"/> object with <see cref="RedirectResult.Permanent"/> set to true
/// and <see cref="RedirectResult.PreserveMethod"/> set to true (<see cref="StatusCodes.Status308PermanentRedirect"/>)
/// and <see cref="RedirectResult.PreserveMethod"/> set to true (<see cref="StatusCodes.Status308PermanentRedirect"/>)
/// using the specified <paramref name="url"/>.
/// </summary>
/// <param name="url">The URL to redirect to.</param>
@ -965,7 +965,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> RedirectToAction(actionName, routeValues: null);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status302Found"/>) to the specified action using the
/// Redirects (<see cref="StatusCodes.Status302Found"/>) to the specified action using the
/// <paramref name="actionName"/> and <paramref name="routeValues"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
@ -975,7 +975,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> RedirectToAction(actionName, controllerName: null, routeValues: routeValues);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status302Found"/>) to the specified action using the
/// Redirects (<see cref="StatusCodes.Status302Found"/>) to the specified action using the
/// <paramref name="actionName"/> and the <paramref name="controllerName"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
@ -1034,15 +1034,15 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to false and <see cref="RedirectToActionResult.PreserveMethod"/>
/// set to true, using the specified <paramref name="actionName"/>, <paramref name="controllerName"/>,
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to false and <see cref="RedirectToActionResult.PreserveMethod"/>
/// set to true, using the specified <paramref name="actionName"/>, <paramref name="controllerName"/>,
/// <paramref name="routeValues"/>, and <paramref name="fragment"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
/// <param name="controllerName">The name of the pageModel.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
public virtual RedirectToActionResult RedirectToActionPreserveMethod(
string actionName = null,
@ -1063,7 +1063,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
@ -1072,8 +1072,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> RedirectToActionPermanent(actionName, routeValues: null);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>
/// and <paramref name="routeValues"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
@ -1083,8 +1083,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> RedirectToActionPermanent(actionName, controllerName: null, routeValues: routeValues);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>
/// and <paramref name="controllerName"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
@ -1094,7 +1094,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> RedirectToActionPermanent(actionName, controllerName, routeValues: null);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>,
/// <paramref name="controllerName"/>, and <paramref name="fragment"/>.
/// </summary>
@ -1109,7 +1109,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> RedirectToActionPermanent(actionName, controllerName, routeValues: null, fragment: fragment);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>,
/// <paramref name="controllerName"/>, and <paramref name="routeValues"/>.
/// </summary>
@ -1124,7 +1124,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> RedirectToActionPermanent(actionName, controllerName, routeValues, fragment: null);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>,
/// <paramref name="controllerName"/>, <paramref name="routeValues"/>, and <paramref name="fragment"/>.
/// </summary>
@ -1151,16 +1151,16 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status308PermanentRedirect"/>) to the specified action with
/// Redirects (<see cref="StatusCodes.Status308PermanentRedirect"/>) to the specified action with
/// <see cref="RedirectToActionResult.Permanent"/> set to true and <see cref="RedirectToActionResult.PreserveMethod"/>
/// set to true, using the specified <paramref name="actionName"/>, <paramref name="controllerName"/>,
/// set to true, using the specified <paramref name="actionName"/>, <paramref name="controllerName"/>,
/// <paramref name="routeValues"/>, and <paramref name="fragment"/>.
/// </summary>
/// <param name="actionName">The name of the action.</param>
/// <param name="controllerName">The name of the pageModel.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
public virtual RedirectToActionResult RedirectToActionPermanentPreserveMethod(
string actionName = null,
string controllerName = null,
@ -1235,14 +1235,14 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified route with
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified route with
/// <see cref="RedirectToRouteResult.Permanent"/> set to false and <see cref="RedirectToRouteResult.PreserveMethod"/>
/// set to true, using the specified <paramref name="routeName"/>, <paramref name="routeValues"/>, and <paramref name="fragment"/>.
/// </summary>
/// <param name="routeName">The name of the route.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
public virtual RedirectToRouteResult RedirectToRoutePreserveMethod(
string routeName = null,
object routeValues = null,
@ -1260,7 +1260,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// <see cref="RedirectToRouteResult.Permanent"/> set to true using the specified <paramref name="routeName"/>.
/// </summary>
/// <param name="routeName">The name of the route.</param>
@ -1269,7 +1269,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> RedirectToRoutePermanent(routeName, routeValues: null);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// <see cref="RedirectToRouteResult.Permanent"/> set to true using the specified <paramref name="routeValues"/>.
/// </summary>
/// <param name="routeValues">The parameters for a route.</param>
@ -1289,7 +1289,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> RedirectToRoutePermanent(routeName, routeValues, fragment: null);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
/// <see cref="RedirectToRouteResult.Permanent"/> set to true using the specified <paramref name="routeName"/>
/// and <paramref name="fragment"/>.
/// </summary>
@ -1327,7 +1327,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <param name="routeName">The name of the route.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
public virtual RedirectToRouteResult RedirectToRoutePermanentPreserveMethod(
string routeName = null,
object routeValues = null,
@ -1494,7 +1494,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
=> new RedirectToPageResult(pageName, pageHandler, routeValues, permanent: true, fragment: fragment);
/// <summary>
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified page with
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified page with
/// <see cref="RedirectToRouteResult.Permanent"/> set to false and <see cref="RedirectToRouteResult.PreserveMethod"/>
/// set to true, using the specified <paramref name="pageName"/>, <paramref name="routeValues"/>, and <paramref name="fragment"/>.
/// </summary>
@ -1502,7 +1502,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <param name="pageHandler">The page handler to redirect to.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
public virtual RedirectToPageResult RedirectToPagePreserveMethod(
string pageName = null,
string pageHandler = null,
@ -1527,7 +1527,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <param name="pageHandler">The page handler to redirect to.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="fragment">The fragment to add to the URL.</param>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
public virtual RedirectToPageResult RedirectToPagePermanentPreserveMethod(
string pageName = null,
string pageHandler = null,
@ -1631,12 +1631,18 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <returns>The created <see cref="PartialViewResult"/> object for the response.</returns>
public virtual PartialViewResult Partial(string viewName, object model)
{
ViewData.Model = model;
// PageModel.ViewData is an instance of ViewDataDictionary<MyPageModel>, but we need an instance
// of ViewDataDictionary<MyPartialViewModel>.
var viewData = new ViewDataDictionary(MetadataProvider, ViewData.ModelState)
{
Model = model,
};
return new PartialViewResult
{
ViewName = viewName,
ViewData = ViewData
ViewData = viewData
};
}

View File

@ -1898,13 +1898,15 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
public void PartialView_WithName()
{
// Arrange
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary());
var modelMetadataProvider = new EmptyModelMetadataProvider();
var viewData = new ViewDataDictionary(modelMetadataProvider, new ModelStateDictionary());
var pageModel = new TestPageModel
{
PageContext = new PageContext
{
ViewData = viewData
}
},
MetadataProvider = modelMetadataProvider,
};
// Act
@ -1913,20 +1915,22 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
// Assert
Assert.NotNull(result);
Assert.Equal("LoginStatus", result.ViewName);
Assert.Same(viewData, result.ViewData);
Assert.Null(result.Model);
}
[Fact]
public void PartialView_WithNameAndModel()
{
// Arrange
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary());
var modelMetadataProvider = new EmptyModelMetadataProvider();
var viewData = new ViewDataDictionary(modelMetadataProvider, new ModelStateDictionary());
var pageModel = new TestPageModel
{
PageContext = new PageContext
{
ViewData = viewData
}
},
MetadataProvider = modelMetadataProvider,
};
var model = new { Username = "Admin" };
@ -1937,7 +1941,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
Assert.NotNull(result);
Assert.Equal("LoginStatus", result.ViewName);
Assert.Equal(model, result.Model);
Assert.Same(viewData, result.ViewData);
}
[Fact]

View File

@ -1700,14 +1700,17 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
public void PartialView_WithName()
{
// Arrange
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary());
var modelMetadataProvider = new EmptyModelMetadataProvider();
var viewData = new ViewDataDictionary(modelMetadataProvider, new ModelStateDictionary());
var pageModel = new TestPage
{
ViewContext = new ViewContext
{
ViewData = viewData
}
},
MetadataProvider = modelMetadataProvider,
};
viewData.Model = pageModel;
// Act
var result = pageModel.Partial("LoginStatus");
@ -1715,21 +1718,24 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
// Assert
Assert.NotNull(result);
Assert.Equal("LoginStatus", result.ViewName);
Assert.Same(viewData, result.ViewData);
Assert.Null(result.Model);
}
[Fact]
public void PartialView_WithNameAndModel()
{
// Arrange
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary());
var modelMetadataProvider = new EmptyModelMetadataProvider();
var viewData = new ViewDataDictionary(modelMetadataProvider, new ModelStateDictionary());
var pageModel = new TestPage
{
ViewContext = new ViewContext
{
ViewData = viewData
}
},
MetadataProvider = modelMetadataProvider,
};
viewData.Model = pageModel;
var model = new { Username = "Admin" };
// Act
@ -1739,7 +1745,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
Assert.NotNull(result);
Assert.Equal("LoginStatus", result.ViewName);
Assert.Equal(model, result.Model);
Assert.Same(viewData, result.ViewData);
}
[Fact]

View File

@ -1,5 +1,5 @@
@page
@model TestModel
@model PagesHome
@{
ViewData["Title"] = "Hello from pages";

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
namespace MvcSandbox
{
public class TestModel : PageModel
public class PagesHome : PageModel
{
public string Name { get; private set; } = "World";

View File

@ -144,23 +144,43 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
}
[Fact]
public async Task Page_Handler_ReturnPartialWithoutModel()
public async Task PageWithoutModel_ReturnPartial()
{
// Act
var document = await Client.GetHtmlDocumentAsync("RenderPartialWithoutModel");
using var document = await Client.GetHtmlDocumentAsync("PageWithoutModelRenderPartial");
var element = document.RequiredQuerySelector("#content");
Assert.Equal("Welcome, Guest", element.TextContent);
Assert.Equal("Hello from Razor Page", element.TextContent);
}
[Fact]
public async Task Page_Handler_ReturnPartialWithModel()
public async Task PageWithModel_Works()
{
// Act
var document = await Client.GetHtmlDocumentAsync("RenderPartialWithModel");
using var document = await Client.GetHtmlDocumentAsync("RenderPartial");
var element = document.RequiredQuerySelector("#content");
Assert.Equal("Welcome, Admin", element.TextContent);
Assert.Equal("Hello from RenderPartialModel", element.TextContent);
}
[Fact]
public async Task PageWithModel_PartialUsingPageModelWorks()
{
// Act
using var document = await Client.GetHtmlDocumentAsync("RenderPartial/UsePageModelAsPartialModel");
var element = document.RequiredQuerySelector("#content");
Assert.Equal("Hello from RenderPartialWithModel", element.TextContent);
}
[Fact]
public async Task PageWithModel_PartialWithNoModel()
{
// Act
using var document = await Client.GetHtmlDocumentAsync("RenderPartial/NoPartialModel");
var element = document.RequiredQuerySelector("#content");
Assert.Equal("Hello default", element.TextContent);
}
[Fact]

View File

@ -0,0 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace RazorPagesWebSite.Models
{
public class RenderPartialModel
{
public string Value { get; set; }
}
}

View File

@ -0,0 +1,6 @@
@page
@using RazorPagesWebSite.Models
@functions {
public IActionResult OnGet() => Partial("_RenderPartial", new RenderPartialModel { Value = "Hello from Razor Page" });
}

View File

@ -0,0 +1,7 @@
@page "{handler?}"
@model RazorPagesWebSite.RenderPartialWithModel
@{
throw new Exception("This should not be called");
}

View File

@ -0,0 +1,20 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RazorPagesWebSite.Models;
namespace RazorPagesWebSite
{
public class RenderPartialWithModel : PageModel
{
public string Text { get; set; } = $"Hello from {nameof(RenderPartialWithModel)}";
public IActionResult OnGet() => Partial("_RenderPartial", new RenderPartialModel { Value = $"Hello from {nameof(RenderPartialModel)}" });
public IActionResult OnGetUsePageModelAsPartialModel() => Partial("_RenderPartialPageModel", this);
public IActionResult OnGetNoPartialModel() => Partial("_RenderPartial");
}
}

View File

@ -1,15 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace RazorPagesWebSite
{
public class RenderPartialWithModel : PageModel
{
public IActionResult OnGet() => Partial("_PartialWithModel", this);
public string Username => "Admin";
}
}

View File

@ -1,4 +0,0 @@
@page
@model RazorPagesWebSite.RenderPartialWithModel
<p>The partial will be loaded here ...</p>

View File

@ -1,5 +0,0 @@
@page
@functions {
public IActionResult OnGet() => Partial("_PartialWithoutModel");
}

View File

@ -1 +0,0 @@
<span id="content">Welcome, Guest</span>

View File

@ -0,0 +1,4 @@
@using RazorPagesWebSite.Models
@model RenderPartialModel
<span id="content">@(Model?.Value ?? "Hello default")</span>

View File

@ -1,3 +1,3 @@
@model RazorPagesWebSite.RenderPartialWithModel
<span id="content">Welcome, @Model.Username</span>
<span id="content">@Model.Text</span>