Rename form-action -> handler
This commit is contained in:
parent
cacee2a837
commit
04fd762943
|
|
@ -429,11 +429,11 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
routeValues["page"] = CalculatePageName(urlHelper.ActionContext, pageName);
|
routeValues["page"] = CalculatePageName(urlHelper.ActionContext, pageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!routeValues.ContainsKey("formaction") &&
|
if (!routeValues.ContainsKey("handler") &&
|
||||||
ambientValues.TryGetValue("formaction", out var formaction))
|
ambientValues.TryGetValue("handler", out var handler))
|
||||||
{
|
{
|
||||||
// Clear out formaction unless it's explicitly specified in the routeValues.
|
// Clear out handler unless it's explicitly specified in the routeValues.
|
||||||
routeValues["formaction"] = null;
|
routeValues["handler"] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return urlHelper.RouteUrl(
|
return urlHelper.RouteUrl(
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
||||||
|
|
||||||
public string HttpMethod { get; set; }
|
public string HttpMethod { get; set; }
|
||||||
|
|
||||||
public string FormAction { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public IList<HandlerParameterDescriptor> Parameters { get; set; }
|
public IList<HandlerParameterDescriptor> Parameters { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
||||||
{
|
{
|
||||||
public class DefaultPageHandlerMethodSelector : IPageHandlerMethodSelector
|
public class DefaultPageHandlerMethodSelector : IPageHandlerMethodSelector
|
||||||
{
|
{
|
||||||
private const string FormAction = "formaction";
|
private const string Handler = "handler";
|
||||||
|
|
||||||
public HandlerMethodDescriptor Select(PageContext context)
|
public HandlerMethodDescriptor Select(PageContext context)
|
||||||
{
|
{
|
||||||
|
|
@ -65,12 +65,12 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
||||||
var handlers = context.ActionDescriptor.HandlerMethods;
|
var handlers = context.ActionDescriptor.HandlerMethods;
|
||||||
List<HandlerMethodDescriptor> handlersToConsider = null;
|
List<HandlerMethodDescriptor> handlersToConsider = null;
|
||||||
|
|
||||||
var formAction = Convert.ToString(context.RouteData.Values[FormAction]);
|
var handlerName = Convert.ToString(context.RouteData.Values[Handler]);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(formAction) &&
|
if (string.IsNullOrEmpty(handlerName) &&
|
||||||
context.HttpContext.Request.Query.TryGetValue(FormAction, out StringValues queryValues))
|
context.HttpContext.Request.Query.TryGetValue(Handler, out StringValues queryValues))
|
||||||
{
|
{
|
||||||
formAction = queryValues[0];
|
handlerName = queryValues[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < handlers.Count; i++)
|
for (var i = 0; i < handlers.Count; i++)
|
||||||
|
|
@ -81,8 +81,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (handler.FormAction != null &&
|
else if (handler.Name != null &&
|
||||||
!handler.FormAction.Equals(formAction, StringComparison.OrdinalIgnoreCase))
|
!handler.Name.Equals(handlerName, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
||||||
|
|
||||||
private static int GetScore(HandlerMethodDescriptor descriptor)
|
private static int GetScore(HandlerMethodDescriptor descriptor)
|
||||||
{
|
{
|
||||||
if (descriptor.FormAction != null)
|
if (descriptor.Name != null)
|
||||||
{
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TryParseHandlerMethod(method.Name, out var httpMethod, out var formAction))
|
if (!TryParseHandlerMethod(method.Name, out var httpMethod, out var handler))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +102,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
var handlerMethodDescriptor = new HandlerMethodDescriptor()
|
var handlerMethodDescriptor = new HandlerMethodDescriptor()
|
||||||
{
|
{
|
||||||
MethodInfo = method,
|
MethodInfo = method,
|
||||||
FormAction = formAction,
|
Name = handler,
|
||||||
HttpMethod = httpMethod,
|
HttpMethod = httpMethod,
|
||||||
Parameters = parameters,
|
Parameters = parameters,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RedirectToPage_DoesNotUseAmbientFormAction()
|
public async Task RedirectToPage_DoesNotUseAmbientHandler()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var expected = "path/to/this-page";
|
var expected = "path/to/this-page";
|
||||||
|
|
@ -192,7 +192,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
Values =
|
Values =
|
||||||
{
|
{
|
||||||
["page"] = expected,
|
["page"] = expected,
|
||||||
["formaction"] = "delete",
|
["handler"] = "delete",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -227,7 +227,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
},
|
},
|
||||||
value =>
|
value =>
|
||||||
{
|
{
|
||||||
Assert.Equal("formaction", value.Key);
|
Assert.Equal("handler", value.Key);
|
||||||
Assert.Null(value.Value);
|
Assert.Null(value.Value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1264,7 +1264,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Page_SetsFormActionToNull_IfValueIsNotSpecifiedInRouteValues()
|
public void Page_SetsHandlerToNull_IfValueIsNotSpecifiedInRouteValues()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
UrlRouteContext actual = null;
|
UrlRouteContext actual = null;
|
||||||
|
|
@ -1273,7 +1273,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
||||||
Values =
|
Values =
|
||||||
{
|
{
|
||||||
{ "page", "ambient-page" },
|
{ "page", "ambient-page" },
|
||||||
{ "formaction", "ambient-formaction" },
|
{ "handler", "ambient-handler" },
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var actionContext = new ActionContext
|
var actionContext = new ActionContext
|
||||||
|
|
@ -1306,13 +1306,13 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
||||||
},
|
},
|
||||||
value =>
|
value =>
|
||||||
{
|
{
|
||||||
Assert.Equal("formaction", value.Key);
|
Assert.Equal("handler", value.Key);
|
||||||
Assert.Null(value.Value);
|
Assert.Null(value.Value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Page_UsesExplicitlySpecifiedFormActionValue()
|
public void Page_UsesExplicitlySpecifiedHandlerValue()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
UrlRouteContext actual = null;
|
UrlRouteContext actual = null;
|
||||||
|
|
@ -1321,7 +1321,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
||||||
Values =
|
Values =
|
||||||
{
|
{
|
||||||
{ "page", "ambient-page" },
|
{ "page", "ambient-page" },
|
||||||
{ "formaction", "ambient-formaction" },
|
{ "handler", "ambient-handler" },
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var actionContext = new ActionContext
|
var actionContext = new ActionContext
|
||||||
|
|
@ -1335,7 +1335,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string page = null;
|
string page = null;
|
||||||
urlHelper.Object.Page(page, new { formaction = "exact-formaction" }, "https", "mytesthost", "#toc");
|
urlHelper.Object.Page(page, new { handler = "exact-handler" }, "https", "mytesthost", "#toc");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
urlHelper.Verify();
|
urlHelper.Verify();
|
||||||
|
|
@ -1344,8 +1344,8 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
||||||
Assert.Collection(Assert.IsType<RouteValueDictionary>(actual.Values),
|
Assert.Collection(Assert.IsType<RouteValueDictionary>(actual.Values),
|
||||||
value =>
|
value =>
|
||||||
{
|
{
|
||||||
Assert.Equal("formaction", value.Key);
|
Assert.Equal("handler", value.Key);
|
||||||
Assert.Equal("exact-formaction", value.Value);
|
Assert.Equal("exact-handler", value.Value);
|
||||||
},
|
},
|
||||||
value =>
|
value =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,27 +21,27 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
public HttpClient Client { get; }
|
public HttpClient Client { get; }
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Page_Handler_FormActionFromQueryString()
|
public async Task Page_Handler_HandlerFromQueryString()
|
||||||
{
|
{
|
||||||
// Arrange & Act
|
// Arrange & Act
|
||||||
var content = await Client.GetStringAsync("http://localhost/HandlerTestPage?formaction=Customer");
|
var content = await Client.GetStringAsync("http://localhost/HandlerTestPage?handler=Customer");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.StartsWith("Method: OnGetCustomer", content.Trim());
|
Assert.StartsWith("Method: OnGetCustomer", content.Trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Page_Handler_FormActionRouteDataChosenOverQueryString()
|
public async Task Page_Handler_HandlerRouteDataChosenOverQueryString()
|
||||||
{
|
{
|
||||||
// Arrange & Act
|
// Arrange & Act
|
||||||
var content = await Client.GetStringAsync("http://localhost/HandlerTestPage/Customer?formaction=ViewCustomer");
|
var content = await Client.GetStringAsync("http://localhost/HandlerTestPage/Customer?handler=ViewCustomer");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.StartsWith("Method: OnGetCustomer", content.Trim());
|
Assert.StartsWith("Method: OnGetCustomer", content.Trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Page_Handler_FormAction()
|
public async Task Page_Handler_Handler()
|
||||||
{
|
{
|
||||||
// Arrange & Act
|
// Arrange & Act
|
||||||
var content = await Client.GetStringAsync("http://localhost/HandlerTestPage/Customer");
|
var content = await Client.GetStringAsync("http://localhost/HandlerTestPage/Customer");
|
||||||
|
|
@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Page_Handler_AsyncFormAction()
|
public async Task Page_Handler_AsyncHandler()
|
||||||
{
|
{
|
||||||
// Arrange & Act
|
// Arrange & Act
|
||||||
var content = await Client.GetStringAsync("http://localhost/HandlerTestPage/ViewCustomer");
|
var content = await Client.GetStringAsync("http://localhost/HandlerTestPage/ViewCustomer");
|
||||||
|
|
@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PageModel_Handler_FormAction()
|
public async Task PageModel_Handler_Handler()
|
||||||
{
|
{
|
||||||
// Arrange & Act
|
// Arrange & Act
|
||||||
var content = await Client.GetStringAsync("http://localhost/ModelHandlerTestPage/Customer");
|
var content = await Client.GetStringAsync("http://localhost/ModelHandlerTestPage/Customer");
|
||||||
|
|
@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PageModel_Handler_AsyncFormAction()
|
public async Task PageModel_Handler_AsyncHandler()
|
||||||
{
|
{
|
||||||
// Arrange & Act
|
// Arrange & Act
|
||||||
var content = await Client.GetStringAsync("http://localhost/ModelHandlerTestPage/ViewCustomer");
|
var content = await Client.GetStringAsync("http://localhost/ModelHandlerTestPage/ViewCustomer");
|
||||||
|
|
@ -800,13 +800,13 @@ Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1[AspNetCore._InjectedP
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RedirectDoesNotIncludeFormActionByDefault()
|
public async Task RedirectDoesNotIncludeHandlerByDefault()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var expected = "/Pages/Redirects/RedirectFromFormActionHandler";
|
var expected = "/Pages/Redirects/RedirectFromHandler";
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await Client.GetAsync("/Pages/Redirects/RedirectFromFormActionHandler/RedirectToPage/10");
|
var response = await Client.GetAsync("/Pages/Redirects/RedirectFromHandler/RedirectToPage/10");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
|
Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
|
||||||
|
|
@ -817,10 +817,10 @@ Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1[AspNetCore._InjectedP
|
||||||
public async Task RedirectToOtherHandlersWorks()
|
public async Task RedirectToOtherHandlersWorks()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var expected = "/Pages/Redirects/RedirectFromFormActionHandler/RedirectToPage/11";
|
var expected = "/Pages/Redirects/RedirectFromHandler/RedirectToPage/11";
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await Client.GetAsync("/Pages/Redirects/RedirectFromFormActionHandler/RedirectToAnotherHandler/11");
|
var response = await Client.GetAsync("/Pages/Redirects/RedirectFromHandler/RedirectToAnotherHandler/11");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
|
Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
|
||||||
|
|
|
||||||
|
|
@ -136,19 +136,19 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Select_ReturnsNullWhenNoHandlerMatchesFormAction()
|
public void Select_ReturnsNullWhenNoHandlerMatchesHandler()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var descriptor1 = new HandlerMethodDescriptor
|
var descriptor1 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Add",
|
Name = "Add",
|
||||||
};
|
};
|
||||||
|
|
||||||
var descriptor2 = new HandlerMethodDescriptor
|
var descriptor2 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Delete",
|
Name = "Delete",
|
||||||
};
|
};
|
||||||
|
|
||||||
var pageContext = new PageContext
|
var pageContext = new PageContext
|
||||||
|
|
@ -165,7 +165,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
{
|
{
|
||||||
Values =
|
Values =
|
||||||
{
|
{
|
||||||
{ "formaction", "update" }
|
{ "handler", "update" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
HttpContext = new DefaultHttpContext
|
HttpContext = new DefaultHttpContext
|
||||||
|
|
@ -186,19 +186,19 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Select_ReturnsHandlerThatMatchesFormAction()
|
public void Select_ReturnsHandlerThatMatchesHandler()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var descriptor1 = new HandlerMethodDescriptor
|
var descriptor1 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Add",
|
Name = "Add",
|
||||||
};
|
};
|
||||||
|
|
||||||
var descriptor2 = new HandlerMethodDescriptor
|
var descriptor2 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Delete",
|
Name = "Delete",
|
||||||
};
|
};
|
||||||
|
|
||||||
var pageContext = new PageContext
|
var pageContext = new PageContext
|
||||||
|
|
@ -215,7 +215,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
{
|
{
|
||||||
Values =
|
Values =
|
||||||
{
|
{
|
||||||
{ "formaction", "Add" }
|
{ "handler", "Add" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
HttpContext = new DefaultHttpContext
|
HttpContext = new DefaultHttpContext
|
||||||
|
|
@ -236,19 +236,19 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Select_FormActionFromQueryString()
|
public void Select_HandlerFromQueryString()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var descriptor1 = new HandlerMethodDescriptor
|
var descriptor1 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Add",
|
Name = "Add",
|
||||||
};
|
};
|
||||||
|
|
||||||
var descriptor2 = new HandlerMethodDescriptor
|
var descriptor2 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Delete",
|
Name = "Delete",
|
||||||
};
|
};
|
||||||
|
|
||||||
var pageContext = new PageContext
|
var pageContext = new PageContext
|
||||||
|
|
@ -267,7 +267,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
Request =
|
Request =
|
||||||
{
|
{
|
||||||
Method = "Post",
|
Method = "Post",
|
||||||
QueryString = new QueryString("?formaction=Delete"),
|
QueryString = new QueryString("?handler=Delete"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -281,19 +281,19 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Select_FormActionConsidersRouteDataFirst()
|
public void Select_HandlerConsidersRouteDataFirst()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var descriptor1 = new HandlerMethodDescriptor
|
var descriptor1 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Add",
|
Name = "Add",
|
||||||
};
|
};
|
||||||
|
|
||||||
var descriptor2 = new HandlerMethodDescriptor
|
var descriptor2 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Delete",
|
Name = "Delete",
|
||||||
};
|
};
|
||||||
|
|
||||||
var pageContext = new PageContext
|
var pageContext = new PageContext
|
||||||
|
|
@ -310,7 +310,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
{
|
{
|
||||||
Values =
|
Values =
|
||||||
{
|
{
|
||||||
{ "formaction", "Add" }
|
{ "handler", "Add" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
HttpContext = new DefaultHttpContext
|
HttpContext = new DefaultHttpContext
|
||||||
|
|
@ -318,7 +318,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
Request =
|
Request =
|
||||||
{
|
{
|
||||||
Method = "Post",
|
Method = "Post",
|
||||||
QueryString = new QueryString("?formaction=Delete"),
|
QueryString = new QueryString("?handler=Delete"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -332,19 +332,19 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Select_FormActionMultipleTimesInQueryString_UsesFirst()
|
public void Select_HandlerMultipleTimesInQueryString_UsesFirst()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var descriptor1 = new HandlerMethodDescriptor
|
var descriptor1 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Add",
|
Name = "Add",
|
||||||
};
|
};
|
||||||
|
|
||||||
var descriptor2 = new HandlerMethodDescriptor
|
var descriptor2 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Delete",
|
Name = "Delete",
|
||||||
};
|
};
|
||||||
|
|
||||||
var pageContext = new PageContext
|
var pageContext = new PageContext
|
||||||
|
|
@ -363,7 +363,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
Request =
|
Request =
|
||||||
{
|
{
|
||||||
Method = "Post",
|
Method = "Post",
|
||||||
QueryString = new QueryString("?formaction=Delete&formaction=Add"),
|
QueryString = new QueryString("?handler=Delete&handler=Add"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -377,13 +377,13 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Select_ReturnsHandlerWithMatchingHttpMethodWithoutAFormAction()
|
public void Select_ReturnsHandlerWithMatchingHttpMethodWithoutAHandler()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var descriptor1 = new HandlerMethodDescriptor
|
var descriptor1 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Subscribe",
|
Name = "Subscribe",
|
||||||
};
|
};
|
||||||
|
|
||||||
var descriptor2 = new HandlerMethodDescriptor
|
var descriptor2 = new HandlerMethodDescriptor
|
||||||
|
|
@ -405,7 +405,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
{
|
{
|
||||||
Values =
|
Values =
|
||||||
{
|
{
|
||||||
{ "formaction", "Add" }
|
{ "handler", "Add" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
HttpContext = new DefaultHttpContext
|
HttpContext = new DefaultHttpContext
|
||||||
|
|
@ -426,7 +426,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Select_WithoutFormAction_ThrowsIfMoreThanOneHandlerMatches()
|
public void Select_WithoutHandler_ThrowsIfMoreThanOneHandlerMatches()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var descriptor1 = new HandlerMethodDescriptor
|
var descriptor1 = new HandlerMethodDescriptor
|
||||||
|
|
@ -478,21 +478,21 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Select_WithFormAction_ThrowsIfMoreThanOneHandlerMatches()
|
public void Select_WithHandler_ThrowsIfMoreThanOneHandlerMatches()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var descriptor1 = new HandlerMethodDescriptor
|
var descriptor1 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
MethodInfo = GetType().GetMethod(nameof(Post)),
|
MethodInfo = GetType().GetMethod(nameof(Post)),
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Add",
|
Name = "Add",
|
||||||
};
|
};
|
||||||
|
|
||||||
var descriptor2 = new HandlerMethodDescriptor
|
var descriptor2 = new HandlerMethodDescriptor
|
||||||
{
|
{
|
||||||
MethodInfo = GetType().GetMethod(nameof(PostAsync)),
|
MethodInfo = GetType().GetMethod(nameof(PostAsync)),
|
||||||
HttpMethod = "POST",
|
HttpMethod = "POST",
|
||||||
FormAction = "Add",
|
Name = "Add",
|
||||||
};
|
};
|
||||||
|
|
||||||
var descriptor3 = new HandlerMethodDescriptor
|
var descriptor3 = new HandlerMethodDescriptor
|
||||||
|
|
@ -515,7 +515,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
{
|
{
|
||||||
Values =
|
Values =
|
||||||
{
|
{
|
||||||
{ "formaction", "Add" }
|
{ "handler", "Add" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
HttpContext = new DefaultHttpContext
|
HttpContext = new DefaultHttpContext
|
||||||
|
|
|
||||||
|
|
@ -377,7 +377,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
public void CreateHandlerMethods_ParsesMethod()
|
public void CreateHandlerMethods_ParsesMethod()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var type = typeof(PageModelWithFormActions).GetTypeInfo();
|
var type = typeof(PageModelWithHandlerNames).GetTypeInfo();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var results = DefaultPageLoader.CreateHandlerMethods(type);
|
var results = DefaultPageLoader.CreateHandlerMethods(type);
|
||||||
|
|
@ -387,13 +387,13 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
results.OrderBy(h => h.MethodInfo.Name),
|
results.OrderBy(h => h.MethodInfo.Name),
|
||||||
handler =>
|
handler =>
|
||||||
{
|
{
|
||||||
Assert.Same(type.GetMethod(nameof(PageModelWithFormActions.OnPutDeleteAsync)), handler.MethodInfo);
|
Assert.Same(type.GetMethod(nameof(PageModelWithHandlerNames.OnPutDeleteAsync)), handler.MethodInfo);
|
||||||
Assert.Equal("Put", handler.HttpMethod);
|
Assert.Equal("Put", handler.HttpMethod);
|
||||||
Assert.Equal("Delete", handler.FormAction.ToString());
|
Assert.Equal("Delete", handler.Name.ToString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PageModelWithFormActions
|
private class PageModelWithHandlerNames
|
||||||
{
|
{
|
||||||
public void OnPutDeleteAsync()
|
public void OnPutDeleteAsync()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@page "{formaction?}"
|
@page "{handler?}"
|
||||||
|
|
||||||
@using Microsoft.AspNetCore.Mvc.Internal
|
@using Microsoft.AspNetCore.Mvc.Internal
|
||||||
@using RazorPagesWebSite
|
@using RazorPagesWebSite
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@page "{formaction?}"
|
@page "{handler?}"
|
||||||
@model RazorPagesWebSite.ModelHandlerTestModel
|
@model RazorPagesWebSite.ModelHandlerTestModel
|
||||||
|
|
||||||
Method: @Model.MethodName
|
Method: @Model.MethodName
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@page "{formaction?}"
|
@page "{handler?}"
|
||||||
@functions
|
@functions
|
||||||
{
|
{
|
||||||
public IActionResult OnGet() => RedirectToPage();
|
public IActionResult OnGet() => RedirectToPage();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@page "{formaction?}/{id:int?}"
|
@page "{handler?}/{id:int?}"
|
||||||
@functions
|
@functions
|
||||||
{
|
{
|
||||||
public IActionResult OnGetRedirectToPage(int id)
|
public IActionResult OnGetRedirectToPage(int id)
|
||||||
|
|
@ -8,6 +8,6 @@
|
||||||
|
|
||||||
public IActionResult OnGetRedirectToAnotherHandler(int id)
|
public IActionResult OnGetRedirectToAnotherHandler(int id)
|
||||||
{
|
{
|
||||||
return RedirectToPage(new { formaction = "RedirectToPage", id = id });
|
return RedirectToPage(new { handler = "RedirectToPage", id = id });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@page "{formaction?}"
|
@page "{handler?}"
|
||||||
@functions
|
@functions
|
||||||
{
|
{
|
||||||
public IActionResult OnGetRedirectToIndex() => RedirectToPage("Index");
|
public IActionResult OnGetRedirectToIndex() => RedirectToPage("Index");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
@page
|
@page
|
||||||
|
|
||||||
<form method="post" asp-page="../../HelloWorld" asp-antiforgery="false"></form>
|
<form method="post" asp-page="../../HelloWorld" asp-antiforgery="false"></form>
|
||||||
<a asp-page="../Redirects/Index" asp-route-formaction="RedirectToIndex" />
|
<a asp-page="../Redirects/Index" asp-route-handler="RedirectToIndex" />
|
||||||
<input type="image" asp-page="../Admin/Index" asp-fragment="my-fragment" />
|
<input type="image" asp-page="../Admin/Index" asp-fragment="my-fragment" />
|
||||||
Loading…
Reference in New Issue