Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter 24 posts 102 karma points
    Feb 22, 2017 @ 06:55
    Peter
    0

    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.

  • Jonas Nikolajsen 17 posts 103 karma points
    Feb 22, 2017 @ 07:12
    Jonas Nikolajsen
    0

    i like partial :)

    fx. Menu in partial Footer in partial

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Feb 22, 2017 @ 08:09
    Alex Skrypnyk
    0

    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

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Feb 22, 2017 @ 08:09
    Dennis Adolfi
    0

    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!

Please Sign in or register to post replies

Write your reply to:

Draft