[HttpPost]
public ActionResult MakeReservation(Reservation model)
{
return CurrentUmbracoPage();
}
When I debug this the MakeReservation Action gets called perfectly well but the model is always empty.. Why? What is the correct way of having a form inside a PartialViewMacro with custom markup?
I think I need to set the Model somehow, but as mentioned before I also need the @inherits Umbraco.Web.Macros.PartialViewMacroPage
there are two ways to get the model back to the controller, sometimes it depends on what else you are doing to the page, as to which one you might choose, but in summary:
I'm not sure if you can do it with Partial view macros, but with straight partial views you can inherit partial view page and pass in your model as the type
@inherits Umbraco.Web.Mvc.UmbracoViewPage
then Model. will be your model, but you still have access to all the Umbraco helpers.
if you can't do this (because it's a macro, or another reason) you can tell your controller that the model name is diffrent in the bindings.
so on your Controller, add [Bind(Prefix="")] to the model argument - matching the name of the variable you assigned your class to.
public ActionResult MakeReservation([Bind(Prefix="reservation")]Reservation model)
if you do that then your model, should be populated. inside the class. and thins like ModelState.IsValid will pass.
This fixed the problem. I was also able to fix the issue by another workaround.
In your Macro view, render a partial view that has the form. Your solution is way more elegant though, rather than having two partial views serving the same purpose.
place a form inside a PartialViewMacroPage
I have a Razor file called Reservation.cshtml. Which is a Macro Partial View.
I would like to have a form inside it. At the start I have
I tried to add the model as well but then I always get an error message
I'm a getting a complete headache why this is so frustrating and complicated. This is what I have so far:
and my Surface Controller:
When I debug this the MakeReservation Action gets called perfectly well but the model is always empty.. Why? What is the correct way of having a form inside a PartialViewMacro with custom markup?
I think I need to set the Model somehow, but as mentioned before I also need the @inherits Umbraco.Web.Macros.PartialViewMacroPage
I hope you guys can help me out!
Thanks
Hi
there are two ways to get the model back to the controller, sometimes it depends on what else you are doing to the page, as to which one you might choose, but in summary:
I'm not sure if you can do it with Partial view macros, but with straight partial views you can inherit partial view page and pass in your model as the type
public ActionResult MakeReservation([Bind(Prefix="reservation")]Reservation model)
if you do that then your model, should be populated. inside the class. and thins like ModelState.IsValid will pass.
This fixed the problem. I was also able to fix the issue by another workaround.
In your Macro view, render a partial view that has the form. Your solution is way more elegant though, rather than having two partial views serving the same purpose.
is working on a reply...