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
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.
You need to pass the view name and the master name, and both of them before the model
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With