3步+确认MVC 4

时间:2013-12-23 20:23:20

标签: asp.net-mvc asp.net-mvc-4

我想设计一个游戏创建控制器/视图过程,其中

用户将获得STEP 1:CREATE GAME然后点击提交以转到步骤2:选择一个位置然后转到步骤3邀请朋友并确认网站的创建。

    在用户单击最终确认按钮之前,不应将
  • 数据提交到数据库

如何使用ASP.NET MVC 4(我目前正在使用EF5并正确生成所有模型等等)。

  • 我应该在每一步之后提交回服务器,并要求显示第二个视图,还是有任何其他的机制来处理这种设计?

非常感谢您的反馈

1 个答案:

答案 0 :(得分:2)

最简单的方法是使用Session和GET / POST请求。看到这个过于简单的例子:

class SignupController : Controller
{
    public ViewResult CreateGame()
    {
        // render the view
    }

    [HttpPost]
    public ViewResult CreateGame(Game model)
    {
        if (ModelState.IsValid)
        {
            // store "model" in session
            return RedirectToAction("location");
        }
        else
        {
            return View("edit", model);
        }
    }

    public ViewResult Location()
    {
        // render the view
    }

    [HttpPost]
    public ViewResult Location(int id, Location location)
    {
        if (ModelState.IsValid)
        {
            RedirectToAction("...")
        }
        else
        {
            return View("edit", location);
        }
    }
}