I'm sorry for the beginner question, but I can't figure this one out.
I'm trying to use my own UserId I have set to navigate around the site, rather than the AspNet.IIdentity
For Example, I have a link to a Profile page which works find when it is hardcoded to the UserId
Snippet from _LoginPartial
@Html.ActionLink("My Profile", "Details", "Users",
routeValues: new { id = 5 } ,
htmlAttributes: new { title = "Profile" })
but I can't get it work dynamically.
I created GetMyUserId action to use, but I just get to work when I call it.
Other attempt for _LoginPartial
@Html.ActionLink("My Profile", "Details", "Users",
routeValues: new { id = Model.GetMyUserId() } ,
htmlAttributes: new { title = "Profile" })
UserContoller
public ActionResult GetMyUserId()
{
string currentUserId = User.Identity.GetUserId();
var userId = db.Users.FirstOrDefault(u =>
u.AspNetId == currentUserId).UserId;
return View(userId);
}
Aucun commentaire:
Enregistrer un commentaire