开发者

asp.net mvc3 RouteToAction() not taking me anywhere

I'm using jquerymobile and asp.net MVC3 razor. I'm somewhat new to this, but figuring things out, I have a very basic route table, with just the ignore route for .axd resources and a default route:

routes.MapRoute(
 "Default",
 "{controller}/{action}/{id}",
 new { controller = "Home", action = "Index", id = "", UrlParameter.Optional }
);

I have an action link that works in an .ascx page:

@Html.ActionLink("Log On", "LogOn", "Account", null, new { @class = "ui-btn-right" })

Now, when I get to the LogOn page, and I complete the account verification, I need to send them to the home开发者_如何学Python page, /Home/Home which works if I type it in the address bar, but I can't seem to get my redirect working in the account controller: return RedirectToAction("Home", "Home");

Thanks for any help!


It sounds like maybe you're posting your form from /Account/LogOn via ajax. That means that when you return RedirectToAction("Home", "Home");, the page wouldn't change. So you just need to not use ajax on the form submit. If my guess is wrong, please post more code so we can get an idea of what the problem is.

It appears from the documentation that jQuery mobile handles form posts via ajax automatically. To prevent this, add the data-ajax="false" attribute to the form element. Documentation here: http://jquerymobile.com/test/docs/forms/forms-sample.html


Given what's written in documentation, could you put your code into a form element and setting its action property to /Account/LogOn ? In order to do that, you may have to convert your ActionLink into a button.


You can check for ajax request in controller:

if(Request.IsAjaxRequest())
{
  //send json object and do navigate in client
  return Json(new {IsLogged = true});
}
else
{ 
  //send redirect html code to browser
  return RedirectToAction("Home", "Home");
}

and in client side, check for json result if you post form by jQuery ajax. I'm not use jquerymobile so I don't know how it work in client side.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜