Reputation: 6019
my problem is about returning a view from a different controller's views list. (MVC3)
first of all I am using areas, but in this case both controllers and views are in the same area.
in the controller; in the DocumentController I am returning a view from BelgeController like
return View("~/Areas/Fin/Views/Belge/Details.cshtml", belgeView);
the problem is in both view folders Document and Belge, there is a partial named edit.cshtml, and when Belge/Details view is rendered, Mvc finds and uses the wrong edit.cshtml, are there any easy ways of referring to the right partial view. I used this approach all along the project, so there are 100s of Edit.cshtml's, so I am looking for an easy fix.
EDIT: So, then the question is how can I pass a model to another controller with RedirectToAction.
Upvotes: 2
Views: 4514
Reputation: 2861
There is are two more options: 1) moving the data around in a tier in the model, so that the model of the BelgeController has the information needed, and call RedirectToAction. 2) hack it with ViewData passed to RedirectToAction.
Upvotes: 0
Reputation: 11285
You could just put the partial view in shared and give it a specific name, ie: BelgeDetails.cshtml
and then you should be able to return View("BelgeDetails", belgeView);
Upvotes: 1
Reputation: 9351
If you need to return a view form another controller, you should be using RedirectToAction. If you need a partial view, each controller should have its own sets of partial views that it uses for its own purposes. Controllers are meant to be self-service and self-reliant. Your pattern should not require different features from different controllers.
That said, it is perfectly reasonable to use jquery ajax calls to OTHER controllers to manage dynamic elements of your page (such as pop up modals and the like). This will allow you to create dynamic page elements without dumping all your code in one controller.
Upvotes: 0
Reputation: 36319
I'm not sure on the use case, but generally speaking a controller shouldn't be serving anything that another controller is responsible for. it should either return a view of its won which has RenderAction calls to the other controller, or it should do a redirect.
Upvotes: 3