Asp.net core 2.1 - Layout controller
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
add a comment |
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
You could use help functions to call the controller such as @Html.Action("method", "controller")
– JamesS
Nov 14 '18 at 17:02
add a comment |
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
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
asp.net-mvc database model-view-controller menu
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 15 '18 at 8:08
FenrirFenrir
677
677
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
You could use help functions to call the controller such as @Html.Action("method", "controller")
– JamesS
Nov 14 '18 at 17:02