4

I have a view where I'm using a specific layout.cshtml file, other than the main shared layout page: "_LayoutExCr"

This is fine for the Get part of the controller:

    //
    // GET: /Exhibitor/Create

    public ActionResult Create()
    {
        return View("Create","_LayoutExCr");
    }

This works fine - and displays the Create view with the specific _LayoutExCr "master" page.

However, in my POST for the Create method, if the wrong access code is entered, I want to return to the same view, using the _LayoutExCr "master" page - but VS2012 Express underlines in Red:

 return View(exhibitor, "_LayoutExCr");

The best overloaded method match for 'System.Web.Mvc.Controller.View(string, string)' has some invalid arguments

    //
    // 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");
    }

Can anyone let me know how to return the model to the view, using that same layout page please?

Thank you,

Mark

4

2 に答える 2

5

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

別のオーバーロードが必要です:

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

最初のパラメーターはビューの名前です。2番目はマスターの名前です。3番目は、ビューに送信するモデルです。

于 2012-10-03T23:06:13.193 に答える
4

モデルの前に、ビュー名マスター名、および両方を渡す必要があります

于 2012-10-03T23:04:45.340 に答える