Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Best way to handle the functionality of a partial in aspnet.core razorpages?

I have a partial, which is a table. I want it in a partial because I want to use it, and its functionality, in more than one place, and inside other pages.

From what I can see, there’s no way to have some sort of controller dedicated to this partial, nor a shared controller. Therefore, all of the functions to populate the models for the table in the partial seemingly can’t be associated with the partial. They need to be duplicated in the PageModel of every page that has the partial.

What would be the best/proper way to achieve what I am asking?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to create a reusable self-contained piece of UI that depends on data or needs its own controller, use a ViewComponent instead of a partial.

These components support DI so you can inject services into them to e.g. obtain data, and they accept parameters too.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading