views:

651

answers:

2

Hi folks,
Here the RedirectToAction() doesn't call the ActionResult Index. Do I need to register a route for this?

[ActionName("onchange")]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult OnChange(int i)
{
    m_NumberOfVisibleItems = i;           
    return RedirectToAction("Index");
}
+5  A: 

Depending on what release of MVC you're using, you don't need the [ActionName] any longer. Also, are you sure you have an "Index" action in that controller and that you don't have an [ActionName] on it that looks like this:

[ActionName("index")]

The way a lot of the stuff in MVC works is through reflection - and I believe capitalization might be an issue with that.

MunkiPhD
Hi, I tried that too as shown below but still it doesnt wrk.... [ActionName("index")] [AcceptVerbs(HttpVerbs.Get)] public ActionResult Index() {....} [ActionName("onchange")] [AcceptVerbs(HttpVerbs.Post)] public ActionResult OnChange(int i) { m_NumberOfVisibleItems = i; return RedirectToAction("index"); }
if you're running the RC of MVC, you don't need to have the [ActionName] decorator anymore. Try getting rid of them. Also try just returning the view: return View("Index", <and the model here>);
MunkiPhD
+3  A: 

I'm not 100% sure, but doesn't RedirectToAction send a 302 redirect to the client? So it wouldn't directly call Index(), only in the next request from the browser.

chris166
You're correct - it's an actual redirect, and as a result, the action Index should be called from scratch... so regardless of how you get there, the Index action should be called. Without more information, it might even be IIS with some sort of redirect setting issue
MunkiPhD