Asp.net core 2.1 - Layout controller










0















I'm learning asp.net core 2.1.
I made a database with Menu table ( ID, Name, Actio,Controller)
And i wanted to pass data from database to menu.
To do that i need a controller who will pass data to view. How to pass these data to _Layout.cshtml? I will need it for child (partial view "Menu").



In templete mvc there is no controller for Layout...










share|improve this question






















  • You could use help functions to call the controller such as @Html.Action("method", "controller")

    – JamesS
    Nov 14 '18 at 17:02
















0















I'm learning asp.net core 2.1.
I made a database with Menu table ( ID, Name, Actio,Controller)
And i wanted to pass data from database to menu.
To do that i need a controller who will pass data to view. How to pass these data to _Layout.cshtml? I will need it for child (partial view "Menu").



In templete mvc there is no controller for Layout...










share|improve this question






















  • You could use help functions to call the controller such as @Html.Action("method", "controller")

    – JamesS
    Nov 14 '18 at 17:02














0












0








0








I'm learning asp.net core 2.1.
I made a database with Menu table ( ID, Name, Actio,Controller)
And i wanted to pass data from database to menu.
To do that i need a controller who will pass data to view. How to pass these data to _Layout.cshtml? I will need it for child (partial view "Menu").



In templete mvc there is no controller for Layout...










share|improve this question














I'm learning asp.net core 2.1.
I made a database with Menu table ( ID, Name, Actio,Controller)
And i wanted to pass data from database to menu.
To do that i need a controller who will pass data to view. How to pass these data to _Layout.cshtml? I will need it for child (partial view "Menu").



In templete mvc there is no controller for Layout...







asp.net-mvc database model-view-controller menu






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 15:01









FenrirFenrir

677




677












  • You could use help functions to call the controller such as @Html.Action("method", "controller")

    – JamesS
    Nov 14 '18 at 17:02


















  • You could use help functions to call the controller such as @Html.Action("method", "controller")

    – JamesS
    Nov 14 '18 at 17:02

















You could use help functions to call the controller such as @Html.Action("method", "controller")

– JamesS
Nov 14 '18 at 17:02






You could use help functions to call the controller such as @Html.Action("method", "controller")

– JamesS
Nov 14 '18 at 17:02













2 Answers
2






active

oldest

votes


















1














In the _layout.cshtml you could simply have a



@Html.Action("Method", "Controller")


in the body which you can use to call another controller. Ideally if this is a navbar etc I'd return a partialView from this method.






share|improve this answer























  • Can't use it in _layout.cshtml for some reason, but I would be awersome it it works ;) IHtmlHelper<dynamic>' does not contain a definition for 'Action' and the best extension method overload 'UrlHelperExtensions.Action(IUrlHelper, string, object)' requires a receiver of type 'IUrlHelper' [project]

    – Fenrir
    Nov 15 '18 at 7:21


















0














I managed to do it by using ViewComponent



https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-2.1



@Html.Action("Method", "Controller") Doesn't work in Asp.Net CORE 2.1






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303140%2fasp-net-core-2-1-layout-controller%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    In the _layout.cshtml you could simply have a



    @Html.Action("Method", "Controller")


    in the body which you can use to call another controller. Ideally if this is a navbar etc I'd return a partialView from this method.






    share|improve this answer























    • Can't use it in _layout.cshtml for some reason, but I would be awersome it it works ;) IHtmlHelper<dynamic>' does not contain a definition for 'Action' and the best extension method overload 'UrlHelperExtensions.Action(IUrlHelper, string, object)' requires a receiver of type 'IUrlHelper' [project]

      – Fenrir
      Nov 15 '18 at 7:21















    1














    In the _layout.cshtml you could simply have a



    @Html.Action("Method", "Controller")


    in the body which you can use to call another controller. Ideally if this is a navbar etc I'd return a partialView from this method.






    share|improve this answer























    • Can't use it in _layout.cshtml for some reason, but I would be awersome it it works ;) IHtmlHelper<dynamic>' does not contain a definition for 'Action' and the best extension method overload 'UrlHelperExtensions.Action(IUrlHelper, string, object)' requires a receiver of type 'IUrlHelper' [project]

      – Fenrir
      Nov 15 '18 at 7:21













    1












    1








    1







    In the _layout.cshtml you could simply have a



    @Html.Action("Method", "Controller")


    in the body which you can use to call another controller. Ideally if this is a navbar etc I'd return a partialView from this method.






    share|improve this answer













    In the _layout.cshtml you could simply have a



    @Html.Action("Method", "Controller")


    in the body which you can use to call another controller. Ideally if this is a navbar etc I'd return a partialView from this method.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 14 '18 at 17:04









    JamesSJamesS

    41718




    41718












    • Can't use it in _layout.cshtml for some reason, but I would be awersome it it works ;) IHtmlHelper<dynamic>' does not contain a definition for 'Action' and the best extension method overload 'UrlHelperExtensions.Action(IUrlHelper, string, object)' requires a receiver of type 'IUrlHelper' [project]

      – Fenrir
      Nov 15 '18 at 7:21

















    • Can't use it in _layout.cshtml for some reason, but I would be awersome it it works ;) IHtmlHelper<dynamic>' does not contain a definition for 'Action' and the best extension method overload 'UrlHelperExtensions.Action(IUrlHelper, string, object)' requires a receiver of type 'IUrlHelper' [project]

      – Fenrir
      Nov 15 '18 at 7:21
















    Can't use it in _layout.cshtml for some reason, but I would be awersome it it works ;) IHtmlHelper<dynamic>' does not contain a definition for 'Action' and the best extension method overload 'UrlHelperExtensions.Action(IUrlHelper, string, object)' requires a receiver of type 'IUrlHelper' [project]

    – Fenrir
    Nov 15 '18 at 7:21





    Can't use it in _layout.cshtml for some reason, but I would be awersome it it works ;) IHtmlHelper<dynamic>' does not contain a definition for 'Action' and the best extension method overload 'UrlHelperExtensions.Action(IUrlHelper, string, object)' requires a receiver of type 'IUrlHelper' [project]

    – Fenrir
    Nov 15 '18 at 7:21













    0














    I managed to do it by using ViewComponent



    https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-2.1



    @Html.Action("Method", "Controller") Doesn't work in Asp.Net CORE 2.1






    share|improve this answer



























      0














      I managed to do it by using ViewComponent



      https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-2.1



      @Html.Action("Method", "Controller") Doesn't work in Asp.Net CORE 2.1






      share|improve this answer

























        0












        0








        0







        I managed to do it by using ViewComponent



        https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-2.1



        @Html.Action("Method", "Controller") Doesn't work in Asp.Net CORE 2.1






        share|improve this answer













        I managed to do it by using ViewComponent



        https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-2.1



        @Html.Action("Method", "Controller") Doesn't work in Asp.Net CORE 2.1







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 8:08









        FenrirFenrir

        677




        677



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303140%2fasp-net-core-2-1-layout-controller%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3