TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mark Tabor
586
2k
464.4k
MVC Partial Views
Apr 3 2019 2:55 AM
I am following this below toturial for generting menu from Database
https://yogeshdotnet.com/dynamically-add-menu-submenus-asp-net-mvc-using-entity-framework/
it works fine for separate project but when i make the Partial view and calling it my code is not running below is my code of partial view and controller
_MenuPartial code:
@model IEnumerable<Pakeeza_Estate.Models.tblMainMenu>
@{
ViewBag.Title =
"Index"
;
Layout =
"~/Views/Shared/_Layout.cshtml"
;
}
@*<link href=
"~/Content/themes/base/jquery-ui.css"
rel=
"stylesheet"
/>*@
<link href=
"~/Content/bootstrap.css"
rel=
"stylesheet"
/>
<script src=
"~/Scripts/jquery-3.3.1.js"
></script>
<script src=
"~/Scripts/bootstrap.min.js"
></script>
@*<script src=
"~/Scripts/jquery-ui-1.12.1.js"
></script>*@
<h2>Index</h2>
<script>
$(document).ready(
function
(){
$(
'.nav li > .sub-menu'
).parent().hover(
function
() {
var
submenu = $(
this
).children(
'.sub-menu'
);
if
($(submenu).is(
':hidden'
)) {
$(submenu).slideDown(200);
}
else
{
$(submenu).slideUp(200);
}
});
})
</script>
<style>
.nav li {
list-style: none;
padding: 5px 10px;
width: 300px;
}
.nav > li {
float
: left;
}
.nav .sub-menu {
display: none;
}
</style>
<ul
class
=
"nav"
>
@{
foreach (
var
item
in
Model)
{
<li>
<a href=
"/Page/@item.MainMenu"
>@item.MainMenu</a>
@
if
(item.tblSubMenus.Count > 0)
{
<ul
class
=
"sub-menu"
>
@foreach (
var
item2
in
item.tblSubMenus)
{
<li><a href=
"/Category/@item2.Controller/@item2.Id"
>@item2.SubMenu</a></li>
}
</ul>
}
</li>
}
}
</ul>
<h2>Index</h2>
My Home controller :
public
PartialViewResult MenuPartial()
{
using
(var db =
new
MenuModel())
{
var d = db.tblMainMenus.Include(c => c.tblSubMenus).ToList();
return
PartialView(
"_MenuPartial"
,d);
}
}
I need urgent response if someone can help me
Reply
Answers (
3
)
How to retrieve data from database in textboxes
user-defined routine or aggregate "DecryptMessage":