If you are trying to update several records at one time, then you'll need to fix the HTML so that the name attribute have indexes. Otherwise, the model binder will be unable to populate the object collection on the server.
I'm using Umbraco, trying to post form but the page just keeps reloading, not hitting the controller
Well... Now, the HTML markup is invalid due to nesting HTML forms. Your original HTML design has many inputs within a single HTML form. Every time you click a button you are submitting every input within the form. This is how HTML forms work.
If you want to update one record at a time, then wrap each record in a form tag. Rather than one big form you'll have several small forms, each representing a record. You should be able to move the BeginUmbracoForm line so it wraps each record.
When the page refreshes all the dropdown values changes to the quantity I selected, however I would prefer only the one record i.e dropdown list change to the value selected and the remaining records (dropdown list to remain at 0) how would
I achieve this?
When the page refreshes all the dropdown values changes to the quantity I selected, however I would prefer only the one record i.e dropdown list change to the value selected and the remaining records (dropdown list to remain at 0) how would I achieve
this?
This is pretty basic MVC stuff brucey... The Controller Action queries the database and fetches a Model. The Model is passed to the View. The View uses the Mode to render the HTML.
I can only see the code that you share. I'm not sure why you are unable to get this information.
Member
256 Points
732 Posts
Pass data from the view to a controller
Mar 10, 2019 01:56 PM|brucey|LINK
When I select a product from the table and click the submit button.
The ProductID and quantity from the dropdown list is passed back to the controller.
But my controller always receives the same ProductID regardless of which product I select.
Any pointer or help much appreciated.
All-Star
52201 Points
23278 Posts
Re: Pass data from the view to a controller
Mar 10, 2019 03:05 PM|mgebhard|LINK
If you are trying to update a single records, then you need to warp each record in a separate <form> element.
If you are trying to update several records at one time, then you'll need to fix the HTML so that the name attribute have indexes. Otherwise, the model binder will be unable to populate the object collection on the server.
Member
256 Points
732 Posts
Re: Pass data from the view to a controller
Mar 10, 2019 03:20 PM|brucey|LINK
Thanks mgebhand, I'm using Umbraco, trying to post form but the page just keeps reloading, not hitting the controller
All-Star
52201 Points
23278 Posts
Re: Pass data from the view to a controller
Mar 10, 2019 03:51 PM|mgebhard|LINK
Well... Now, the HTML markup is invalid due to nesting HTML forms. Your original HTML design has many inputs within a single HTML form. Every time you click a button you are submitting every input within the form. This is how HTML forms work.
If you want to update one record at a time, then wrap each record in a form tag. Rather than one big form you'll have several small forms, each representing a record. You should be able to move the BeginUmbracoForm line so it wraps each record.
I assume you'll also need to re-query the data and pass it to the View so when the page refreshes the quantity is in sync.
Member
256 Points
732 Posts
Re: Pass data from the view to a controller
Mar 10, 2019 04:35 PM|brucey|LINK
Thanks mgebhard, everything is working ok now :)
When the page refreshes all the dropdown values changes to the quantity I selected, however I would prefer only the one record i.e dropdown list change to the value selected and the remaining records (dropdown list to remain at 0) how would I achieve this?
All-Star
52201 Points
23278 Posts
Re: Pass data from the view to a controller
Mar 10, 2019 05:02 PM|mgebhard|LINK
This is pretty basic MVC stuff brucey... The Controller Action queries the database and fetches a Model. The Model is passed to the View. The View uses the Mode to render the HTML.
I can only see the code that you share. I'm not sure why you are unable to get this information.