Kevin himch
Kevin himch

Reputation: 297

Display variable property inside partial view

I am returning user variable to my Partial view but i dont know how can i display that variable data inside my mvc view. Suppose i have two property on this "user" (FirstName and LastName) variable then can i access that like @user.FirstName and @user.LastName inside my view? I tried it but not works. Please advice solution for that. Thanks in advance

[ChildActionOnly]
public PartialViewResult _UserNav(string id)
 {
   using (BlexzWebDbEntities db = new BlexzWebDbEntities())
     {
       var user = db.Users.Where(x => x.Email == id).FirstOrDefault();
       return PartialView("_UserNav", user);
     }
 }

Upvotes: 0

Views: 19

Answers (1)

Guilherme
Guilherme

Reputation: 5341

You need to declare the type of the model, for example:

@model User

Then, access like that:

@Model.FirstName

Upvotes: 2

Related Questions