Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC Return to same view, using a specific layout page

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

like image 274
Mark Avatar asked Jan 16 '23 09:01

Mark


2 Answers

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

You want a different overload:

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

1st parameter is the name of the view. 2nd is the name of the master. 3rd is the model you want to send to the view.

like image 85
Gromer Avatar answered Jan 17 '23 23:01

Gromer


You need to pass the view name and the master name, and both of them before the model

like image 27
SLaks Avatar answered Jan 17 '23 23:01

SLaks