开发者

Why is RedirectToAction and Index method in same area searching for view in root?

开发者 https://www.devze.com 2023-04-04 06:56 出处:网络
I am having problems with using RedirectToAction(\"Index\") in a controller within an Admin area. When the Redirect occurs, it hits a breakpoint within the Index method on the controller so I know th

I am having problems with using RedirectToAction("Index") in a controller within an Admin area.

When the Redirect occurs, it hits a breakpoint within the Index method on the controller so I know the redirect is working. However, it fails to find the view.

    public ActionResult Index(int? Id)
    {
        var model = _leadOriginService.GetEditorModel(Id);
        return View(mode开发者_C百科l);
    }

The exception shows a list of the views it is trying to resolve in the root and not in the area. It seems that it has lost the context of the area it is in.

Any ideas why this doesn't work?


I think you need to call RedirectToAction in another fashion as MVC might not be possible to infer the Area from the way you are calling it, so you need to specify it..

Try

RedirectToAction("Index", "yourController", new {Area="Admin"})

Or

RedirectToAction("Index", new {Area="Admin"})
0

精彩评论

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