In my _Layout.cshtml
view I have
@using SiteNET.Utilities
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>"SomeTitle"</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<!-- Favicons -->
<link rel="apple-touch-icon-precomposed"
sizes="256x256"
href="@Url.Content("~/Content/Images/SiteRetro256.png")">
<link rel="shortcut icon"
href="@Url.Content("~/Content/Icons/SiteRetro.ico")">
</head>
<body>
<div class="container">
<div class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button"
class="navbar-toggle"
data-toggle="collapse"
data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
</button>
@Html.ActionLink(SiteNET.Utilities.Constants.Site,
"Index", "Home", null, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="@Url.MakeActive("Home")">
@Html.ActionLink("Home", "Index", "Home")
</li>
<li class="@Url.MakeActive("Index", "Contacts")">
@Html.ActionLink("Contacts", "Index", "Contacts")
</li>
</ul>
@Html.Action("_LoginPartial", "Account") <- THIS LINE
</div>
</div> <!--container-fluid-->
</div> <!--navbar-->
@RenderBody()
<hr />
...
</div>
</body>
</html>
My aim is be able to load a view model into my _LoginPartial
view. So I have added the following to my AccountController
class
[ChildActionOnly]
public ActionResult _LoginPartial()
{
ApplicationUser user = null;
ManageUserViewModel model = null;
string userID = User.Identity.GetUserId() ?? String.Empty;
if (!String.IsNullOrEmpty(userID))
{
user = UserManager.FindById(userID);
model = new ManageUserViewModel();
model.IsAdmin = user.IsAdmin;
}
return PartialView(model);
}
But this does not call this method from
@Html.Action("_LoginPartial", "Account")`
I have read this answer and have swapped the
@Html.Action("_LoginPartial", "Account")
to
@Html.Action("_LoginPartial", "Account", new { area = "" })
as the controller is not in the "Shared" folder. I have also tried
@Html.Action("_LoginPartial", "Account", new { area = "Controllers" })`
but I am just getting a browser error:
The page isn't redirecting properly
What am I doing wrong here?
Thanks for your time.
Edit. following @markpSmith's suggestion, I have attempted to use
@{ Html.RenderAction("_LoginPartial", "Account"); }
_but this give the same error. _