If you think that the functionallity should belong in a controller, the most common controllers for Umbraco is SurfaceControllers or RenderMvcControllers (also called Route Hijacking). Have a look at these docs for the difference between these two:
It could be however that you can place your code in a Helper class, which is just a standard .cs class with a bunch of properties and methods used across your application and you then avoid redundant coding.
For both the controllers and the helpers, the quick and easy way is to place these files in the /AppCode folder of your solution (this folder might not exists in your solution right now, then you can just create it). Every class you place in this folder will be compiled at runtime, which can be convinient sometimes if your not using a developing tool like Visual Studio. If you dont want to place them in the /AppCode folder, you can place them anywhere in you solution, but then you'll need to build your solution everytime you make a change for the changes to take affect, a process your probobly used to if your used to standard MVC developing with Visual Studio.
As Jonas mentiond, Partials can be the soltion. However it depends on the functionallity. You should'nt place to much functionallity in your views, because it affects the performance negative. It could be that you can use a helper AND a Partial, where the helper handles all the functionallity and the partial only handles the rendering. This could make your code more readable and easier to navigate, but as mentioned, it depends on your code.
To Much Functionality In The View - Where To Put It
Hi
At the moment we have some functionality in the (Master) view which I think doesn't really belong there.
But there should it be put?
It is generally some kind of functionality you might put in a controller.
i like partial :)
fx. Menu in partial Footer in partial
Hi Peter
Move all code what should be in controller to controllers, look what controllers are available - https://our.umbraco.org/documentation/reference/routing/custom-controllers
Thanks,
Alex
Hi Peter.
If you think that the functionallity should belong in a controller, the most common controllers for Umbraco is SurfaceControllers or RenderMvcControllers (also called Route Hijacking). Have a look at these docs for the difference between these two:
SurfaceController: https://our.umbraco.org/documentation/Reference/Routing/surface-controllers
RenderMvcController: https://our.umbraco.org/documentation/reference/routing/custom-controllers
It could be however that you can place your code in a Helper class, which is just a standard .cs class with a bunch of properties and methods used across your application and you then avoid redundant coding.
For both the controllers and the helpers, the quick and easy way is to place these files in the /AppCode folder of your solution (this folder might not exists in your solution right now, then you can just create it). Every class you place in this folder will be compiled at runtime, which can be convinient sometimes if your not using a developing tool like Visual Studio. If you dont want to place them in the /AppCode folder, you can place them anywhere in you solution, but then you'll need to build your solution everytime you make a change for the changes to take affect, a process your probobly used to if your used to standard MVC developing with Visual Studio.
As Jonas mentiond, Partials can be the soltion. However it depends on the functionallity. You should'nt place to much functionallity in your views, because it affects the performance negative. It could be that you can use a helper AND a Partial, where the helper handles all the functionallity and the partial only handles the rendering. This could make your code more readable and easier to navigate, but as mentioned, it depends on your code.
Hope this was helpful. Have a great day!
is working on a reply...