【问题标题】:MVC Url not pathing correctlyMVC Url 路径不正确
【发布时间】:2013-09-27 11:22:39
【问题描述】:

我有一个链接去

<a class="k-link" href="/UserView/EditByName?UserName=MVCTest6">Profile</a>

当链接被点击时,它会转到这个

URL: http://localhost:3256/MVCTest6/Create

当我以管理员用户身份登录时有效。 (该文件夹在将其分开的 web.config 中没有安全性)。此链接实际上适用于页面的另一部分。

该用户也已经存在并已通过身份验证。

可以解释一下吗?

【问题讨论】:

  • 你能发布控制器的部分代码吗?
  • @Athiban... 谢谢这让我看到了控件忘记了如果尚未创建用户配置文件,我有重定向代码。

标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing url-routing


【解决方案1】:

我明白了!这就是问题所在,

 return RedirectToAction("Create", User.Identity.Name);

你正在使用这个重载RedirectToAction("Action", "Contoller");

所以后面的部分作为控制器。如果您尝试将值传递给另一个操作,请尝试符合您要求的其他重载,这必须像

 return RedirectToAction("Create", new {UserName = User.Identity.Name});

【讨论】:

    【解决方案2】:

    如果没有创建用户配置文件,我忘记了我有重定向的逻辑。这是造成问题的原因。我的测试用户没有设置配置文件,所以它正在重定向到创建页面

    public ActionResult EditByName(string userName)//EditByName
            {
                if (User.Identity.IsAuthenticated)
                {
                    UserModel usermodel = repository.Get(User.Identity.Name);// db.UserModels.Find(id);
                    if (usermodel == null)
                    {
                        return RedirectToAction("Create", User.Identity.Name);
                    }
                    return View(usermodel);
                }
                else { return RedirectToAction("Login", controllerName: "AccountView"); }
            }
    

    【讨论】:

    • 用这部分编辑问题,而不是作为答案发布
    • 对不起...不会再这样做了
    猜你喜欢
    • 1970-01-01
    • 2018-06-18
    • 2017-11-02
    • 1970-01-01
    • 2019-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    相关资源
    最近更新 更多