Model Binding - Not in a controller
# help-with-other
n
Hi All, I'm hoping some clever'er brains than mine can help me find a solution to the following: I have a "block" that can be put on variety of pages, however this block has pagination/filtering etc and is essentially a listing block. Now, I'm looking to make the submissions of the filters/pagination requests update the query string and do a form get inorder to reload the page with updated data. Historically (pre .Net Core) I could do this easily because of Surface Controllers and Child Actions, which allowed me to use .Net Model Binding for my filters etc. However this is not available with View components. What I'm trying to understand/figure out, is within a view component, if I have access to the HttpContext/Request/Query string, how can I manually call the .Net Model Binding routine inorder to generate a strongly type model from the query string, taking advantage of how .Net can safely parse the query string without me have to do it all manually one field at a time. I was looking into how I could create instances of things like the "ComplextObjectModelBinder" or other model binders, and then create a default binding context and pass in the query string from the request. Has anyone tried to do this, or got ideas on how I can approach it. The reason for trying this is I can't override all the controllers for all the doc types just to handle this block... or could I? Could an alternative be to replace the default render controller so a custom action was always available?
s
I am not familiar enough with the block system but I just wanted to note that you can replace our default RenderController so you are in effect hijacking all routes, maybe that takes you closer to a good solution? https://docs.umbraco.com/umbraco-cms/reference/routing/custom-controllers#replace-umbracos-default-rendercontroller
n
Yeah, it was after I was writing the post I wondered about the overriden default controller. I might give that a go as it might be a simpler solution.
d
Hey @Nik, I have pagination in Umbootstrap that may help, if I understand correctly you want the pagination to append to the query string? e. g. https://umbootstrap.com/features/feature-internal-links-pagination/?page=2#pagination
4 Views