Asp.Net Core 2 中是否有与 Response.Redirect("~/Controller/")
等效的函数?
我不想使用ViewComponent
。相反,我想从 View 中调用 Controller 和操作方法。
@using Jahan.Blog.Web.Mvc.Models
@{
ViewBag.Title = "Home Page";
}
<header>
<h1> Blog </h1>
</header>
<div class="blog-description">
<p>...</p>
</div>
@{ Response.Redirect("~/Article/");}
最佳答案
如果在 Controller 方法中尝试这个:
RedirectToAction("yourActionName", "YourControllerName");
或者:
Url.Action("YourActionName", "YourControllerName");
这也可以与 AppStart -> RouteConfig.cs 文件中定义的参数一起使用
i.e
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "YourControllerName", action = "YourActionName", id =
UrlParameter.Optional }
);
要传递参数,只需为 get 方法添加新关键字
Url.Action("YourActionName", "YourControllerName", new { id = id });
用于Post方法使用
Url.Action("YourActionName", "YourControllerName", new { "your variable" = id });
关于asp.net - Asp.Net Core 2 中是否有相当于 Response.Redirect ("~/Controller/"的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48141038/