ASP.Net MVC 使用特定布局页面返回同一视图

Mar*_*ark 4 asp.net asp.net-mvc razor

我有一个视图,其中使用的是特定的layout.cshtml 文件,而不是主要的共享布局页面:“_LayoutExCr”

这对于控制器的 Get 部分来说很好:

    //
    // GET: /Exhibitor/Create

    public ActionResult Create()
    {
        return View("Create","_LayoutExCr");
    }
Run Code Online (Sandbox Code Playgroud)

这工作正常 - 并显示带有特定 _LayoutExCr“主”页面的创建视图。

但是,在我的 Create 方法的 POST 中,如果输入了错误的访问代码,我想使用 _LayoutExCr“主”页面返回相同的视图 - 但 VS2012 Express 用红色下划线:

 return View(exhibitor, "_LayoutExCr");
Run Code Online (Sandbox Code Playgroud)

'System.Web.Mvc.Controller.View(string, string)' 的最佳重载方法匹配有一些无效参数

    //
    // POST: /Exhibitor/Create

    [HttpPost]
    public ActionResult Create(Exhibitor exhibitor)
    {
        if (ModelState.IsValid)
        {
            if (exhibitor.AccessCode == "myaccesscode")
            {
                db.Exhibitors.Add(exhibitor);
                db.SaveChanges();
                return RedirectToAction("Thankyou");
            }
            else
            {
                ModelState.AddModelError("", "The Access Code provided is incorrect.");
                return View(exhibitor, "_LayoutExCr");
            }

        }

        return View(exhibitor, "_LayoutExCr");
    }
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何使用相同的布局页面将模型返回到视图?

谢谢你,

标记

Gro*_*mer 5

http://msdn.microsoft.com/en-us/library/dd492244(v=vs.98).aspx

你想要一个不同的重载:

return View("Create", "_LayoutExCr", exhibitor);

第一个参数是视图的名称。第二个是主人的名字。第三个是您要发送到视图的模型。