title: Get UserId in MVC to use in View
body: <p>I have the following problem in my MVC 5 web app. I used database first approach and the entity framwork to create a table <code>[accountlist]</code> that has a foreign key relationship on <code>[UserId]</code> to the <code>[Id]</code> column from <code>[AspNetUsers]</code>. Right now the pertaining <code>accountlist.cshtml</code> contains a dropdown menu. I also tried <code>@Html.HiddenFor(model =&gt; model.UserId, new { @Value = HttpContext.Current.User.Identity.Name})</code> but the problem is how that I need the correct userid and not the username (I don't want the <code>[UserName]</code> from <code>[AspNetUsers]</code> to be an primary key).</p>
  
  <p>Unfortunately, <code>HttpContext.Current.User.Identity.GetUserId()</code> as suggested in this <a href="https://stackoverflow.com/questions/18448637/how-to-get-current-user-and-how-to-use-user-class-in-mvc5">solution</a> says that Identity contains no definition for GetUserId().</p>
  
  <p>Does anyone has solution?</p>
  
  <p>Thanks in advance!</p>