Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > MVC DefaultModelBinder not working View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
ian-inkdigitalagency - 3/6/2013 5:04:34 AM
   
MVC DefaultModelBinder not working
Hi all,

I have setup my project to use the Razor view engine for MVC as the following post details..
Using-MVC-Razor-With-Kentico-CMS-7

I have setup 2 actions on my controller..
[HttpGet]
public ActionResult Create()
{
var example= new CustomClass();

return View(example);
}

[HttpPost]
public ActionResult CreatePost(CustomClass example)
{
if (!ModelState.IsValid)
return View(example);

return RedirectToAction("SomeView");
}

I have view for Create which has a basic form to post to the CreateProperty Action. If the model is invalid I want to return the invalid model to the view displaying the validation messages.

The problem I am having is that the DefaultModelBinder doesn't seem to be working at all. I cannot get into the CreatePost action. If I change the parameter type in CreatePost from CustomClass to FormCollection it works but I lose the benefits that the DefaultModelBinder brings.

Does anyone have any ideas?

cheers
Ian

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 3/24/2013 12:25:22 PM
   
RE:MVC DefaultModelBinder not working
Hello,

Our developers tried that setup an it seems to work fine...
Could you please add an information how does your view and model object look like?
If you don't want to send it publicly, a simplified non-working code could also help.

Thank you in advance.

Regards,
Zdenek

User avatar
Certified Developer v7
Certified  Developer v7
ian-inkdigitalagency - 3/25/2013 6:22:35 AM
   
RE:MVC DefaultModelBinder not working
Hi Zdenek,

Thanks for getting back to me. One of your developers sent me an example and I have managed to get this working.

There was an issue with the way I had setup the Document alias for the Create action.

Cheers

Ian