首页 > 解决方案 > 与 Sammy.js 相关的返回视图问题

问题描述

我正在使用 sammy.js 构建一个 SPA,关于 Sammy 的路由如下;

this.get(/#\/user\/profile/i, function (context) {
    titleContent.html("User Profile");
    document.title = "User Profile";
    getPage("#/user/profile", "/User/Profile", context);
});

我有一个 GET 和 POST 视图,用于更新用户帐户的信息;

[Authorize, HttpGet, Route("User/Profile")]
    new public ActionResult Profile()
    {
    //do some stuff
    return View(vm);
}

[HttpPost, Authorize, Route("User/Profile")]
    new public ActionResult Profile(UserProfileViewModel vm)
    {
        if (!ModelState.IsValid)
            return View(vm);
    
    //other code if valid modelstate
    return View(vm);

}

现在,然后!Modelstate.IsValid,它将视图返回为“/User/Profile”,而不是“/#/User/Profile”。

如何使用已使用错误消息更新的 ViewModel 返回实际的 Sammy 注册路由(“/#/User/Profile”)?

标签: c#asp.netmodel-view-controller

解决方案


推荐阅读