0

In Brad Wilson's post

http://webanonymizer.info/browse.php?b=5&u=Oi8vYnJhZHdpbHNvbi50eXBlcGFkLmNvbS9ibG9nLzIwMDgvMDgvcGFydGlhbC1yZW5kZXJpLmh0bWw%3D

he listed all the overloaded method for Html.RenderPartial(), but none takes the controller name as parameter.

For my application, I would like to specify the controller name when calling RenderPartial. Is there any way to get around this problem other than moving my view to /Shared folder?

2 Answers 2

1

The Render methods are intended to render Views. The idea is that the Controller deals with the request, conjures up a Model and hands that Model off to the View. At that point, the Controller's work is done.

I think it is an indication of a design flaw if the View needs to know anything about the Controller. Can you share more about what it is that you are trying to accomplish?

I often find that when dealing with well-designed frameworks (such as the MVC framework), if it feels like the framework is fighting you, you are probably going about the task in the wrong way. This has happened to me a lot, and stepping back and asking myself what it is that I'm really trying to accomplish often leads to new insights.

But if you really must, you can always put the Controller name in the ViewData...

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

6 Comments

I am doing the customer-review module for an e-commerce application. The goal is to enable a seller to see reviews regarding to his/her products. Now, I have a master page Seller.master contains a partial view "SellerMenu". My scenario is follows: 1. A request for viewing reviews is directed to ReviewController which holds the ReviewRepository. 2. ReviewController handles the request, and returns a View which is under Views/Review folder. 3. Because this view is for sellers, I want to apply the Seller.Master as well, and of course I got an exception from the browser.
My approach could be totally off. Can you tell me what is wrong from the design point of view?
When you return a View from the Controller, there's an overload to the Controller.View method that allows you specify the name of a master page. Isn't that what you need, then?
Specifying the name of master page is not my problem. My problem is not able to render the partial view from a different View folder. Any way, as you said, it's more likely a problem in my design. Maybe I should handle the request with SellerController instead.
So you are saying that the problem is that in the context of your View, the user control cannot be found because it is contained in a different folder?
|
0

You could consider using Html.RenderAction in ASP.NET MVC Futures.

1 Comment

RenderAction can certainly do what I want here. However, I feel it "poisoned" the Master page. Not being able to achieve my goal without using shortcuts might be the "smell" of my design.

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.