asp.net,如何从 localhost/Controller1/Index 转到 localhost/Controller2/Details/{ID}?
asp.net, how can i go from localhost/Controller1/Index to localhost/Controller2/Details/{ID}?
我正在尝试从 https://localhost:44383/Reservations/Index
到 https://localhost:44383/Bikes/Details/{Id}
但是我不知道我需要什么htmlactionlink
我认为这是正确的:@Html.ActionLink("Details", "Details", "Bikes", new { Id = item.Reservation.Bike_Id })
有人能告诉我如何从 Reservation 控制器转到 details 控制器并提供 details 和 id 作为参数吗?
@Html.ActionLink("Details", "Details" , "Bikes")
将我带到 localhost/Bikes/Details
。但是我也需要后面的id
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);
}
你试过了吗
@Html.ActionLink("Details", "Bikes", "Details", new { id = item.Reservation.Bike_Id }, null)
请注意,我在传递的 id 参数中使用了小写 'i'。我还认为您在这里的控制器名称和操作名称是错误的。
还值得注意的是,在传递参数时,您应该使用空重载来更正操作 link。
我正在尝试从 https://localhost:44383/Reservations/Index
到 https://localhost:44383/Bikes/Details/{Id}
但是我不知道我需要什么htmlactionlink
我认为这是正确的:@Html.ActionLink("Details", "Details", "Bikes", new { Id = item.Reservation.Bike_Id })
有人能告诉我如何从 Reservation 控制器转到 details 控制器并提供 details 和 id 作为参数吗?
@Html.ActionLink("Details", "Details" , "Bikes")
将我带到 localhost/Bikes/Details
。但是我也需要后面的id
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);
}
你试过了吗
@Html.ActionLink("Details", "Bikes", "Details", new { id = item.Reservation.Bike_Id }, null)
请注意,我在传递的 id 参数中使用了小写 'i'。我还认为您在这里的控制器名称和操作名称是错误的。
还值得注意的是,在传递参数时,您应该使用空重载来更正操作 link。