2

I'm working on a page in an Asp.NET MVC 3 application. I have an action in one controller called Alarm. That controller is called Dispatch. For various reasons, I need to modify this action so it displays its results in a view from another controller called Read. This view is called Details.

How can I make the Alarm action return that view? I tried

return View( "Read/Details", vm );

but that displayed this error message:

The view 'Read/Details' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Dispatch/Read/Details.aspx ~/Views/Dispatch/Read/Details.ascx ~/Views/Shared/Read/Details.aspx ~/Views/Shared/Read/Details.ascx ~/Views/Dispatch/Read/Details.cshtml ~/Views/Dispatch/Read/Details.vbhtml ~/Views/Shared/Read/Details.cshtml ~/Views/Shared/Read/Details.vbhtml

What's the right way to do this?

0

2 Answers 2

4

Use full path instead

return View("~/Views/Read/Details.cshtml", vm);
Sign up to request clarification or add additional context in comments.

Comments

0

You can redirect to an action on another controller:

return RedirectToAction("ActionName", "ControllerName", routeValues);

Obviously replace the action and controller names with the appropriate values and routeValues will contain whatever parameters the action requires. So if your vm variable is just an integer Id, your code would look something like this:

return RedirectToAction("ActionName", "ControllerName", new { id = 1234 });

Further reading: http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction(v=vs.118).aspx

2 Comments

While the RedirectToAction works, it changes the URL. I want the different view to display but at the current URL. Kalyan's answer, as well as one in the other question, do that.
Ahh, you're right. I'll leave this answer here in case anyone else is looking for this behavior.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.