Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Model binding issue after submitting MVC form rendered from block (MVC6)

Vote:
 

Hi everyone,

I am facing the problem of how to call a controller's action methot correctly (with POST data) from a MVC form. Data are always null. From the httpcontext I can see that the form contains data, but it is trying to bind the dato to wrong model - it is trying to find model with properties like "CurrentPage.MainContentArea.FooProperty".

In order to be able somehow fetched the data I had to use attribute [BindProperty(Name = "CurrentPage.MainContentArea.FooProperty")] 

I tried to inspire by the foundation project in git repo https://github.com/episerver/Foundation but to my surprise the similar logic is not working even there! (testing on GroupCreationBlockComponent). To make that block even render I had to change the path to it's view. Then I also created a new controller for the submit action method but the model binding is not working here too.

What I need is: Create block which will render an MVC form and send those data to Action method

I guess I don't need to share the source code, the foundation project is a good example.

#295363
Jan 26, 2023 8:32
Vote:
 

This is becasue it is a ViewCompoent and they do not respond to post.  If you want to post something use a regular controller.

#295387
Jan 26, 2023 17:26
Vote:
 

Hi Mark, yes, I mentioned that in my question:
"To make that block even render I had to change the path to it's view. Then I also created a new controller for the submit action method but the model binding is not working here too."

#295430
Jan 27, 2023 7:15
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.