What I want to do is have 2 different controllers, client and test_client. The client controller is already built and I want to create a test_client controller that i can use to play around with the UI of the client and adjust it as needed. I am mainly trying to get around the validation i have built into the client and its dependence on an admin controller that loads the data.
so i want the test_client controller to load a sample data set and then render the client controller's index view so i can adjust the clients UI. That is all.
I tried this in the test_clients index method:
class TestClient
def index
render :template => 'client/index'
end
end
but i get an error because it cannot find the client partials as it is looking in the current controllers view for them...
So I have looked into this already and most people say that you should never make such a call but i think that this case is a reasonable usage...I just need to figure out how to get it to work.
A Sitecore Controller Rendering is more complex than a View Rendering, mainly in that it requires a controller action. The rendering definition item includes both a controller name and controller action to execute. The controller action is then responsible for returning the correct view. A basic controller rendering method.
In this article, we will explain how to display a view from another controller in ASP.NET MVC with an example and sample code. In this example, we have created a sample login page, and based on Login we are redirecting to another controller action method. Open Visual Studio. Click on the file in the menu and select new Project .
A Controller Rendering definition item. A Sitecore Controller Rendering is more complex than a View Rendering, mainly in that it requires a controller action. The rendering definition item includes both a controller name and controller action to execute. The controller action is then responsible for returning the correct view.
By default, ASP.NET MVC checks first in Views [Controller_Dir], but after that, if it doesn't find the view, it checks in ViewsShared. The shared directory is there specifically to share Views across multiple controllers. Just add your View to the Shared subdirectory and you're good to go.
You will need to adjust your view so that the path to the partial you need is in the form 'controller/partial'
. In this case probably 'client/partial'
. Then you can simply use render 'client/index'
as before.
So say somewhere in your view you have this:
<%= render :partial => 'info' %>
You will want to change it to this:
<%= render :partial => 'client/info' %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With