我有哪裏我使用的是特定layout.cshtml文件的視圖,比主共享頁面佈局等:「_LayoutExCr」ASP.Net MVC返回到相同的觀點,使用特定的佈局
這是罰款控制器的獲取部分:
//
// GET: /Exhibitor/Create
public ActionResult Create()
{
return View("Create","_LayoutExCr");
}
這工作得很好 - 並顯示與特定_LayoutExCr「主」頁面創建視圖。
然而,在我的帖子的創建方法,如果輸入了錯誤的接入碼,我想回到同一個視圖中,使用_LayoutExCr「主人」頁面 - 但VS2012快速強調在紅:
return View(exhibitor, "_LayoutExCr");
爲 'System.Web.Mvc.Controller.View(字符串,字符串)' 最好的重載的方法匹配有一些無效 參數
//
// 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");
}
任何人都可以讓我知道如何將模型返回到視圖,請使用相同的佈局頁面嗎?
謝謝
馬克
爲什麼不在視圖中設置佈局? – SLaks
嗨 - 沒有真正的原因 - 說實話,這是我第一次使用MVC中的默認佈局以外的任何東西 - 並不知道如何!謝謝,Mark – Mark