Razor 链接到另一个.cshtml
我需要从Home.cshtml链接到Login.cshtml页面,但它似乎找不到链接 Home.cshtmlRazor 链接到另一个.cshtml,razor,hyperlink,asp.net-mvc-4,Razor,Hyperlink,Asp.net Mvc 4,我需要从Home.cshtml链接到Login.cshtml页面,但它似乎找不到链接 Home.cshtml @{ Layout = "~/Shared/Master.cshtml"; ViewBag.Title = "Home"; } @section menu { <a href="/Login">Login</a> } 线路图 routes.MapRoute( name: "De
@{
Layout = "~/Shared/Master.cshtml";
ViewBag.Title = "Home";
}
@section menu
{
<a href="/Login">Login</a>
}
线路图
routes.MapRoute(
name: "Default",
url: "",
defaults: new { controller = "Home", action = "Home" }
);
项目结构:
您的登录页面将位于/Home/Login 如果您想要为/Login创建一个页面,则需要创建一个名为LoginController的新控制器,该控制器的操作结果方法为Index 您需要具备以下功能才能为RouteConfig中的页面提供服务:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/",
defaults: new { controller = "Home", action = "Home" }
);
这也会对默认主页进行排序它似乎找不到/home/Login自添加ActionResult登录后,您是否构建了解决方案?如果你试着用HTML.ActionLink来建立你的链接,你是说ActionResult登录在我当前的HomeController中?你把RouteConfig文件弄得乱七八糟了吗?这意味着/Home/Login应该可以工作,你得到了什么错误?我在我的主要帖子中添加了我的RouteConfig。如果这是不正确的,我如何获得Home.cshtml作为主页?
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/",
defaults: new { controller = "Home", action = "Home" }
);