title: manage account mvc app c#
body: <p>I am trying to get my ‘manage’ link to redirect to the relevant account.
  I have a BankAccsController which works for fine for viewing details for a logged in user and to see both accounts held in the database, but what I want to do is be able to click the corresponding button to the right of the account and for it to take me to the details for that specific account. I know I will have to create a new method to replace the current two ‘ViewCurrent and ViewSavings’ and use parameters but I’m unsure how to do it and can’t find the correct words to type it into Google.</p>
  
  <p><a href="https://i.stack.imgur.com/s1KUb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s1KUb.png" alt="ePic of my accounts page"></a></p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>//View all accounts of logged in user
      [Authorize]
      public ActionResult Index()
      {
          var userId = User.Identity.GetUserId();
          var bankAccs = db.BankAccs.Where(a =&gt; a.AccUserId == userId).ToList();
          return View(bankAccs.ToList());
      }
  
      ////View current account  of logged in user
      public ActionResult ViewCurrent()
      {
  
          var userId = User.Identity.GetUserId();
          ViewModels.CurrentAccVm bankVm = new ViewModels.CurrentAccVm();
          bankVm.BankAccList = db.BankAccs.Where(a =&gt; a.AccUserId == userId &amp;&amp; a.AccTypeId == 1).ToList();
          bankVm.UserName = User.Identity.GetUserName();
          return View(bankVm);
      }
  
      ////View Savings account  of logged in user
      public ActionResult ViewSavings()
      {
          var userId = User.Identity.GetUserId();
          ViewModels.CurrentAccVm bankVm = new ViewModels.CurrentAccVm();
          bankVm.BankAccList = db.BankAccs.Where(a =&gt; a.AccUserId == userId &amp;&amp; a.AccTypeId == 2).ToList();
          bankVm.UserName = User.Identity.GetUserName();
          return View(bankVm);
      }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>     @model IEnumerable&lt;Atm11.Models.BankAcc&gt;
  
      @{
          ViewBag.Title = "Index";
      }
  
      &lt;h2&gt;Index&lt;/h2&gt;
  
      &lt;p&gt;
          @Html.ActionLink("Create New", "Create")
      &lt;/p&gt;
      &lt;table class="table"&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Balance)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.AccType.AccountType)
              &lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
  
      @foreach (var item in Model) {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Balance)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.AccType.AccountType)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.ActionLink("Manage", "ViewAccounts", new { id = item.Id })
  
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  
      &lt;/table&gt;
  </code></pre>