具有Views子文件夹的MVC Controller子文件夹

时间:2019-05-06 16:12:00

标签: asp.net asp.net-mvc

如果有子文件夹,如何从一页移动到另一页?

控制器:

Controllers

观看次数:

Views

动作:

AccountController

...
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> Login...
        {

            return View("~/Views/Account/Login.chtml");
        }

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> Login...
            {
                ...
            return View("~/Views/Account/Login.chtml", login);
        }
       ...
       public IActionResult TypeRegister()
        {
            return View("~/Views/Account/TypeRegister.chtml");
        }
    }
}

发件人: 索引页[HomeController]

<li><a asp-controller="Account" asp-action="Login">Log In</a></li>

收件人: 登录页面[Accounts / AccountController]

1 个答案:

答案 0 :(得分:2)

您做对了,但是有错字。文件扩展名是.cshtml而不是.chtml

Views/[ControllerName]/[ViewName].cshtml Views/Shared/[ViewName].cshtml

https://docs.microsoft.com/en-us/aspnet/core/mvc/views/overview?view=aspnetcore-2.2