Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何重定向到asp.net core razor页面(无路由)_C#_Asp.net Core_Razor Pages - Fatal编程技术网

C# 如何重定向到asp.net core razor页面(无路由)

C# 如何重定向到asp.net core razor页面(无路由),c#,asp.net-core,razor-pages,C#,Asp.net Core,Razor Pages,这里我有一个razor cs页面: public IActionResult OnPost(){ if (!ModelState.IsValid) { return Page(); } return RedirectToPage('Pages/index.cshtml'); } 和cshtml页面: @page @using RazorPages @model IndexModel <form method="POST"> <input ty

这里我有一个razor cs页面:

public IActionResult OnPost(){
  if (!ModelState.IsValid) {
    return Page(); 
  }

  return RedirectToPage('Pages/index.cshtml'); 

}
和cshtml页面:

@page
@using RazorPages

@model IndexModel
<form method="POST">
  <input type="submit" id="Submit">
</form>
@page
@使用剃须刀
@模型索引模型
我想重定向到表单提交上的同一页,但我一直收到400个错误。是否可以在不使用路由的情况下重定向到url中的cshtml文件?

在视图中尝试此操作

@using (Html.BeginForm())
{
   <input type="submit" id="Submit">
}
@使用(Html.BeginForm())
{
}
查看MS页面

页面的URL路径的关联由页面在文件系统中的位置决定。下表显示了Razor页面路径和匹配的URL:

File name path matching URL --------------------------- ---------------------- /Pages/Index.cshtml / or /Index /Pages/Contact.cshtml /Contact /Pages/Store/Contact.cshtml /Store/Contact /Pages/Store/Index.cshtml /Store or /Store/Index 文件名路径匹配URL --------------------------- ---------------------- /Pages/Index.cshtml/或/Index /页面/Contact.cshtml/Contact /页面/Store/Contact.cshtml/Store/Contact /页面/Store/Index.cshtml/Store或/Store/Index 页面的URL生成支持相对名称。下表显示了使用不同的RedirectToPage参数从中选择的索引页 页面/Customers/Create.cshtml:

RedirectToPage(x) Page ------------------------ --------------------- RedirectToPage("/Index") Pages/Index RedirectToPage("./Index"); Pages/Customers/Index RedirectToPage("../Index") Pages/Index RedirectToPage("Index") Pages/Customers/Index 重定向Topage(x)页 ------------------------ --------------------- 重定向网页(“/Index”)页面/索引 重定向Topage(“/索引”);页面/客户/索引 重定向Topage(“../Index”)页面/索引 重定向Topage(“索引”)页面/客户/索引 @罗曼·博克罗夫斯基 这可能太旧了,但如果要重定向到某个区域,则应:

return RedirectToPage ( "/Page", new { Area = "AreaName" } );

如果要在执行某些操作后重定向到其他页面:

return Redirect("~/Page/YourAction");

返回视图(viewname);这是PageModelRemove“Pages”类型的razor页面从重定向路径中删除“Pages”。这在重定向Topage('Pages/index.cshtml')时起作用;更改为重定向Topage(“索引”);您也可以只使用RedirectToPage();您好,我可以问您我们应该如何重定向到区域:/areas/MyArea/pages/Index.cshtml中的页面吗?我最大的问题是我认为路径中需要“pages”或“/pages”。一旦我把它取下来,一切都正常了。从重定向路径中删除“页面”。