开发者

ASP.NET MVC - Wrong redirecting, how to debug?

I am stuck with redirecting problem in ASP.NET MVC project. I have mapped tables via LINQtoSQL and each has unique ID as primary key.

I am implementing functionallity of 'CREATE'. Basically, after new value is added into SQL table (which means I pressed Save button), I want to be redirected to Details of this freshly added item.

Here's little code how I am doing it :

[AcceptVerbs(HttpVerbs.Post), Authorize]
public ActionResult Create(Item item) {
....
return RedirectToAction("Details", new { id = item.ItemID });

Trouble is, I am never redirected to Details view (I have Details.aspx view for items).

When I check CallHierarchy in Visual Studio (2010 pro) the hierarchy is indeed little strange, like this :

RedirectToAction(string,object)

  • Calls To 'RedirectToAction'
    • Create
      • Calls To Create (no results)
      • Calls From Create (methods of created instance. From there I'll get back to 'RedirectToAction' and to 'Calls to Create' and 'Calls From Create' etc. etc. - loop
    • Edit
  • Calls From 'RedirectToAction'

I am looking for some tools or more specifically 'know how' (since VS probably has some tools) to debug this kind of situations.

PS: rooting is default :"{controller}/{action}/{id}",

Thanks


Checck your routes with Phil Haack's Route Debugger. Make sure that the correct route is being used, and the correct controller method is being called.


Use the debugger to step to the line where RedirectToAction is called. Confirm that the line is realy hit. Press F5 to continue after it.

Once the code is executed check in Firebug under network if a 302 is emitted. See what is in the details for the request.

If no 302 is emitted I would try return RedirectToAction("Index") just to know if the call to details is wrong or there is another error.


You would need in the same controller

public ActionResult Details(int id)
{
    return View();
}

in additon to the Details.aspx view.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜