I am not sure if and how one can do this but in my controller I have:
[HttpGet]
public ActionResult Detail(int userId)
{
UserDetailViewModel user = new UserDetailViewModel();
user.UserId = userId;
user.Email = Email;
return View(user);
}
My UserDetailViewModel:
namespace Zinc.Web.Areas.Admin.ViewModels.User
public class UserDetailViewModel
{
[LocalizedRequired]
[DisplayName("UserId")]
public int UserId { get; set; }
[LocalizedRequired]
[DisplayName("Email")]
public string Email { get; set; }
}
I have the Id of the user but need to get the rest of the details like email, name, surname etc.. I have just put email down for now..
Must I pass into the view another model that has those details?
You would need to add all those properties into your view model (i.e.
UserDetailViewModel).Then create a method which can get the values and set them to the properties using the
idas a parameter:Example of
GetUser:The advantage of applying this to a general Model rather than your View Model is that this can be applied to other View Models without having to make multiple methods for data access of the same data.