-1

I am trying to go from https://localhost:44383/Reservations/Index to https://localhost:44383/Bikes/Details/{Id} But I don't know what html actionlink i need.

I thought this was the right one: @Html.ActionLink("Details", "Details", "Bikes", new { Id = item.Reservation.Bike_Id })

Can someone tell me how to go from Reservation controller to details controller and give details and id as parameter?

@Html.ActionLink("Details", "Details" , "Bikes") brings me to localhost/Bikes/Details. But I need the id at the back as well

    public ActionResult Details(int? id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        Bike bike = db.Bikes.Find(id);
        if (bike == null)
        {
            return HttpNotFound();
        }
        return View(bike);
    }
kevin
  • 21
  • 4
  • The first details is what you see as a link. `@Html.ActionLink("Details", "Details" , "Bikes")` this brings me to `localhost/Bikes/Details`. But i need the id at the back as well :( – kevin Apr 22 '20 at 09:17
  • Lets see the controller action the one you want to call – JamesS Apr 22 '20 at 09:24
  • updated with the controller of bike details – kevin Apr 22 '20 at 09:26

1 Answers1

0

Have you tried

@Html.ActionLink("Details", "Bikes", "Details", new { id  = item.Reservation.Bike_Id }, null)

Note that I've used a lowercase 'i' in the id parameter passed. I also think you have the controller name and the action name the wrong way around here.

Also worth noting that as you are passing parameters, you should use a null overload to correct the action link.

JamesS
  • 2,167
  • 1
  • 11
  • 29
  • that brings me to `https://localhost:44383/Reservations/Details?Length=5` – kevin Apr 22 '20 at 09:28
  • that brings me to `https://localhost:44383/Reservations/Bikes?Length=7` – kevin Apr 22 '20 at 09:33
  • @kevin In that case, what you will need is an overload. Adding `null` as the forth input in this link should solve your problem. This will be because if you use other parameters, it assumes the third argument is the route values and the 4th are the html attributes. Adding the 5th will correct this. – JamesS Apr 22 '20 at 09:35