views:

71

answers:

2

I'm new to working with MVC so please don't assume I know anything.

I am picking up a project that has much already written in MVC and I am trying to add some things to it.

On one View there is a line

<% Html.RenderAction("List", "Image", new { id = Model.JobId, all = true });  %>

I see a List.ascx under the Image directory. I see the List method on the view controller.

I'd like to render the results of that list method to a different ascx file. (AssignImage.ascx) I realize I could add another method on the controller, but it seems like I should have a way of using the same method but a different view.

+2  A: 

In your Action method

if (isList) return PartialView("List"); else return PartialView("AssignImage");

Yuriy Faktorovich
so the Action method determines the view? it seems like i should be able to just ask for the data somehow from the controller and let the the view determine the layout... maybe I am thinking about it backwards/traditional asp.net way.
Jeff Martin
Yes, the action determines the View. The View, according to the MVC pattern, should be very stupid and not make determinations like that.
Yuriy Faktorovich
+1  A: 

If you don't mind reusing (or duplicating) some code I'd probably just make a new action to deal with this.

I don't think I would change the action to pass in another parameter (the action already is taking 2: a jobId and a boolean). You'd probably have to change existing code somewhere to account for a third parameter.

Assuming the action is just giving you a list of records I don't see how adding a new action with one line of LINQ (or however you are getting data) would offend the DRY... especially if it makes the code easier to maintain by not mixing too many functions in one action. If its too offensive, then you can refactor the actions to call some common method.

Sailing Judo