0

Again an easy question for ASP.NET MVC 2.

public ActionResult MyAction(MyModel model)
    {
        if (ModelState.IsValid)
        {
           // do great stuff and redirect somewhere else

        }

        // model has errors
        return View("~/Home/Index", model);
    }

The question is that I want to return a view which is outside of the current controller. I do not want to redirect since I want to hand the model to the next view. The "View"-method does not allow to specify a controller. The above "return View..." obviously doesn't work.

I am sure that there's a simple workaround here :)

3 Answers 3

2

If your view is used by more than one controller put it in the Shared views folder instead of a specific controller's view folder. Then you can simply refer to it by it's name, if different than the name of the action.

Sign up to request clarification or add additional context in comments.

Comments

1
public ActionResult MyAction(MyModel model)
{
    if(ModelState.IsValid)
    {
        return RedirectAction("...");
    }
    ControllerContext.RouteData.Values["controller"] = "SomeOtherController";
    return View("Index");
}

will guide you do Index view under SomeOtherController folder.

Comments

0

You'll need an extension

return View("~/Path/To/View.aspx", model);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.