在这里,我有一个剃须刀cs页面:
public IActionResult OnPost(){
if (!ModelState.IsValid) {
return Page();
}
return RedirectToPage('Pages/index.cshtml');
}
Run Code Online (Sandbox Code Playgroud)
和一个cshtml页面:
@page
@using RazorPages
@model IndexModel
<form method="POST">
<input type="submit" id="Submit">
</form>
Run Code Online (Sandbox Code Playgroud)
我想重定向到表单提交的同一页面,但我不断收到400错误。是否可以在不使用路由的情况下进行重定向,而只需转到url中的cshtml文件?
查看 MS 页面 https://docs.microsoft.com/en-us/aspnet/core/mvc/razor-pages/?tabs=visual-studio
URL 路径与页面的关联由页面在文件系统中的位置确定。下表显示了 Razor 页面路径和匹配的 URL:
文件名路径匹配 URL ———————————————————————— /Pages/Index.cshtml / 或 /Index /Pages/Contact.cshtml /Contact /Pages/Store/Contact.cshtml /Store/Contact /Pages/Store/Index.cshtml /Store 或 /Store/Index
页面的 URL 生成支持相对名称。下表显示了使用 Pages/Customers/Create.cshtml 中的不同 RedirectToPage 参数选择了哪个索引页面:
RedirectToPage(x) 页面 ------------- --------------------- RedirectToPage("/Index") 页数/索引 RedirectToPage("./Index"); 页面/客户/索引 RedirectToPage("../Index") 页数/索引 RedirectToPage("Index") 页面/客户/索引
小智 7
@Roman Pokrovskij这可能太旧了,但是如果您想重定向到某个区域,则应该:
return RedirectToPage ( "/Page", new { Area = "AreaName" } );
Run Code Online (Sandbox Code Playgroud)
在视图中试试这个;
@using (Html.BeginForm())
{
<input type="submit" id="Submit">
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20548 次 |
最近记录: |