Reputation: 9568
I want to show some user details on the right top position of the page after the user logged in using Forms Authentication.
The login info is reused on every page (part of the layout page).
I created a controller and partialview and it will be rendered using the RenderAction call. If I run the web app, I don't see that the HTML is rendered. I do see that the controller is invoked, but the function not....
(Note: ExtendedController is derived from ASP.NET MVC's Controller class)
Controller:
public class LoginInfoController : ExtendedController
{
private IDependencyFactory factory;
public LoginInfoController(IDependencyFactory factory)
: base(factory)
{
this.factory = factory;
}
[ChildActionOnly]
public PartialViewResult UserInfo()
{
var viewModel = new LogonInfoViewModel
{
Fullname = "Patrick Peters"
};
return PartialView(viewModel);
}
}
The _Layout.cshtml:
<div class="span2 offset7">
<div class="bottom">
@{Html.RenderAction("UserInfo", "LoginInfo");}
</div>
</div>
The _LoginInfo.cshtml:
<div class="user" style="text-align: right">
<cut HTML....>
</div>
Upvotes: 1
Views: 1192
Reputation: 47375
Try this instead:
[ChildActionOnly]
public PartialViewResult UserInfo()
{
var viewModel = new LogonInfoViewModel
{
Fullname = "Patrick Peters"
};
return PartialView("_LoginInfo", viewModel); // <-- change is in this line
}
When you call return PartialView(viewModel)
, MVC assumes that your viewname will be the same as the action method name, in the controller's views folder. Your solution should work if you rename "_LoginInfo.cshtml" to "UserInfo.cshtml" and make sure that it is in the Views/LoginInfo folder.
Upvotes: 1