there.. I'am really confused about Layout and PartialLayout. I don't know what wrong I'am doing. When I login as Admin I can se all links even this Admin links ("Register", "Role", "Department" and "Manage") plus Logout link. So far so good. But when I click any link of Admin links then my Layout changes as I'am not Admin I mean I see only "Home" , "About" "kontakt" ANd very confusing my logout link changes to Login after all I'am logged. So I'am logged but shows me Login instead. Then if I click "Home"..or About.. then I see all links again and Logout link. Please I'am new to this staffs and show me by coding if it's Ok, becouse I couldn't fix this problem in many hours ...
Here is my one of the admin html "Role"
@model IEnumerable<MyApiDemo.Models.RoleViewModel>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
</table>
In my Index.cshtml , _Layout is included. Here is my _Layout.cshtml
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application namn", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
@Html.Partial("_LoginPartial")
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year</p>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
And this is my _LoginPartial.cshtml
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated && ViewData.ContainsKey("FullName"))
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
<ul class="nav navbar-nav navbar-right">
@if (HttpContext.Current.User.IsInRole("Admin"))
{
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
<li>@Html.ActionLink("Role", "Index", "Role")</li>
<li>@Html.ActionLink("Department", "Index", "Department")</li>
<li>@Html.ActionLink("Manage", "Pass", "Account")</li>
}
<li>
@Html.ActionLink("Welcome back " + (ViewData["FullName"]) + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Logout</a></li>
</ul>
}
}
else
{
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Login", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
}
ViewDatacontain a value forFullName? (and why are you using that condition anyway?)elseblock is generated - i.e. yourLoginlink, not theLogOff. And what do you mean you have created two kind of Layout Views - you have not (your_LoginPartialis a partial view, not a layout)