c# - Controller 中的 ASP.NET Core MVC 子操作

标签 c# asp.net-core asp.net-core-mvc

我有一个带有用户方法的管理 Controller 。我想在此方法中添加一个带有新 View 的"new"子操作。 URL 应如下所示:/administration/users/new

我该怎么做?

感谢您的帮助!

最佳答案

这真的只是一个关于路由的问题。只需在管理 Controller 中添加一个方法,并通过 Route 属性告诉 MVC 路由是什么。例如:

public class AdministrationController : Controller
{
    public ActionResult Users()
    {
    }

    [Route("users/new")] //This is the important part here
    public ActionResult NewUser()
    {
    }
}

您也可以在 Startup.cs 类中配置路由,但我发现使用属性路由更容易。参见 here获取更多信息。

关于c# - Controller 中的 ASP.NET Core MVC 子操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53988496/

相关文章:

c# - 脚手架上的 MVC 防伪 token 错误

c# - 将两个 Asp.Net Core API 合并到一个应用程序中

c# - 如何在 asp.net core 中为 JwtBearer 和 System.IdentityModel.Tokens.Jwt 自定义 bearer header 关键字?

asp.net-core - 从 asp.net 核心身份获取 applicationuser 的属性

asp.net-core - MVC 6 中多个网站的通用 wwwroot 文件夹

c# - Entity Framework 6 迁移与 MVC 6 RC 1

c# - 使用 asp.net 查找一周中的星期一的日期

c# - WPF MVVMLight Messenger UI 线程问题

c# - 我的 ActionScript 有什么问题?

C# azure : How to set Azure timeout and retry policy when running locally?