asp.net MVC 4在数据库中创建新项目后重定向到详细信息?

use*_*259 3 c# asp.net-mvc-4

希望有人可以帮助我.

我正在创建一个网站,人们可以在这里进行保存到数据库的预订.

我遇到的问题是,当有人在网站上创建预订时,它会将他们带回到该控制器的索引视图,该视图显示数据库中的所有内容.

但是,我希望它们在点击"创建"按钮后将其带到预订的详细信息视图中.

我希望这很清楚.我的创建代码是:

     // POST: /Booking/Create

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create(Booking booking)
    {
        if (ModelState.IsValid)
        {
            db.Bookings.Add(booking);
            db.SaveChanges();

            return RedirectToAction("Index");
        }

        return View(booking);
    }
Run Code Online (Sandbox Code Playgroud)

如果我尝试更换

     return RedirectToAction("Index");
Run Code Online (Sandbox Code Playgroud)

     return RedirectToAction("Details");
Run Code Online (Sandbox Code Playgroud)

我收到错误,但必须有一个简单的方法吗?任何人都可以指出我出错的地方吗?

谢谢.

nat*_*ehr 13

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Booking booking)
{
    if (ModelState.IsValid)
    {
        db.Bookings.Add(booking);
        db.SaveChanges();

        return RedirectToAction("Details", new { bookingId = booking.Id });
    }

    return View(booking);
}

public ActionResult Details(int bookingId)
{
    var details = GetBookingDetails(bookingId); //Load details
    return View(details);
}
Run Code Online (Sandbox Code Playgroud)