NavbarItem.cs
public class NavBarItems
{
public class NavbarAdminViewModel
{
public List<ParentNavbarItem> ParentItems { get; set; }
public List<ChildNavbarItem> ChildItems { get; set; }
public List<SelectListItem> Roles { get; set; }
}
public class NavbarRoleItem
{
public string RoleId { get; set; }
public string RoleName { get; set; }
}
public class ParentNavbarItem
{
public string ID { get; set; }
public string ObjectID { get; set; }
public string Controller { get; set; }
public bool IsDropdown { get; set; }
public string Role { get; set; }
public int Priority { get; set; }
public ICollection<ChildNavbarItem> Children { get; set; }
}
public class ChildNavbarItem
{
public string ID { get; set; }
public string ObjectID { get; set; }
public string Controller { get; set; }
public string Views { get; set; }
public string Role { get; set; }
}
}
ToolController.cs
public async Task<IActionResult> UserAccess()
{
var viewModel = new NavbarAdminViewModel
{
Roles = GetRoles(),
ParentItems = await _context.WMS_ParentNavbar
.Include(p => p.Children)
.ToListAsync(),
ChildItems = new List<ChildNavbarItem>()
};
return View(viewModel);
}
UserAccess.cshtml
@model WMS_Frontend.Models.NavBarItems.NavbarAdminViewModel
@using WMS_Frontend.Helpers;
<h1>Navbar Administration</h1>
<p>
<a asp-action="CreateParentItem">Add New Parent Item</a>
</p>
<table class="table">
<thead>
<tr>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var role in Model.Roles)
{
<tr>
<td>@RoleHelper.GetRoleName(role.ToString())</td>
<td>
<a asp-action="EditParentItem" asp-route-id="@role">Edit</a> |
<a asp-action="DeleteParentItem" asp-route-id="@role">Delete</a>
</td>
</tr>
}
</tbody>
</table>
RoleHelper.cs
public static class RoleHelper
{
public static string GetRoleName(string roleId)
{
switch (roleId)
{
case "1": return "Administrator";
case "2": return "Staff";
case "3": return "Bin Collector";
case "4": return "Resident";
default: return "";
}
}
}
Database:
ParentNavbar Table
ChildNavbar Table
Error :
Hello Everyone can someone help with my error. The purpose of this I want to manage this navbar by Administrator this is serve as my UserAccess of the system. I want that the administrator manage this UserAccess. Now I trying to get the details of the parent with corresponding child and display it to the table. But I encountered an error “SqlException: Invalid column name ‘ParentNavbarItemID’. Invalid column name ‘ParentNavbarItemID’.” but i check in the modal i don’t have a ParentNavbarItemID im not sure where this column came from.
2