我已阅读并实施了几乎所有解决方案。但它似乎对我来说还不够。
当我运行我的应用程序时(在localhost中)
1)。登录页面来了,
http://localhost/ (called login.cshtml)
Controller: LoginCotroller
action : Login
2)。对于经过身份验证的用户,它会重定向到用户位置页面
http://localhost/Locations/UserLocations (called locations.cshtml)
Controller: Locations
actions : UserLocations
现在复杂的部分来了,
选择特定位置后,用户会重定向到Dashboard.cshtml。 并且同时angularjs进入了画面。 Dashboard.cshtml标头有两个链接
1.Change Locations //@Html.ActionLink
2.SignOut //@Html.ActionLink
3)显示仪表板
http://localhost/Home/Dashboard
Controller: Home
action : Dashboard
直到这里一切正常。
但问题是两个链接上面没有正常工作。当我点击链接时,它会更改Url,但不会将我重定向到特定的操作方法。
Note: when url is changed, I have to go to browser's address bar and
explicitly hit enter to redirect myself to destination( I don't want that)
我已经尝试了几乎所有可能的方法,但仍然不适合我。
我所做的是,
更改位置链接,
1)@Html.ActionLink("Change Location", "UserLocations", "Locations");
2)@Html.ActionLink("Change Location", "UserLocations", "Locations",null,null);
3)@Html.ActionLink("Change Location", "UserLocations", "Locations",new{},new{});
用于SignOut链接,
1)@Html.ActionLink("SignOut", "Logout", "Login");
2)@Html.ActionLink("SignOut", "Logout", "Login",null,null);
3)@Html.ActionLink("SignOut", "Logout", "Login",new{},{});
我有以下路由的MVC
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Customers", "{customer}/Login", new { controller = "Login", action = "Login" }, null);
routes.MapRoute(
name: "",
url: "{angularRoute}",
defaults: new
{
controller = "Home",
action = "Dashboard",
id = UrlParameter.Optional
}
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Login",
action = "Login",
id = UrlParameter.Optional
}
);
}
}
答案 0 :(得分:2)
如果您想简单地阻止Angular处理链接而改为使用MVC路由,请将目标添加到self:
@Html.ActionLink("Search", "Search", "Home", null, new { target = "_self" })
答案 1 :(得分:0)
而不是所有这三个:
1)@Html.ActionLink("Change Location", "UserLocations", "Locations");
2)@Html.ActionLink("Change Location", "UserLocations", "Locations",null,null);
3)@Html.ActionLink("Change Location", "UserLocations", "Locations",new{},new{});

尝试更简单的方法来定义ActionLinks。
@Html.ActionLink("Change Location", "UserLocations", new { controller = "Locations" });

修改强>
routes.MapRoute("Customers", "{customer}/Login", new { controller = "Login", action = "Login" }, null);

您希望通过这条路线实现什么目标?