I need to get some data from my DB from _LoginPartial.cshtml
. Is it possible to use @model
in _LoginPartial.cshtml
? Or how is it done? Just by @using WebApp.Services
and then directly retrieve the data from the service? Or it there a more elegant way doing this?
I tried to do it with @model
but didn't work because the @model
in _LoginPartial.cshtml
got overridden by another @model
. _LoginPartial.cshtml
is "injected" into every page/view.
Views/Shared/_LoginPartial.cshtml
@model WebApp.ViewModels.LoginPartialViewModel
@Html.ActionLink("" + User.Identity.Name + " (" + Model.Email + ")", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
ViewModels/ManageViewModels.cs
public class LoginPartialViewModel
{
public string Email = new UserService().ReadCurrent().Email;
}
And the Views/Shared/_LoginPartial.cshtml
is used in Views/Shared/_Layout.cshtml
like this:
@Html.Partial("_LoginPartial")
Could this be done with @model
or would i have to do some nasty thing in Views/Shared/_LoginPartial.cshtml
like this:
@using WebApp.Services
var userService = new UserService();
var email = userService.Read(User.Identity.GetUserId()).Email;
@Html.ActionLink("" + User.Identity.Name + " (" + email + ")", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })