Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial View within Partial View in MVC: Good or bad practice?

What are the implications of having a partial view within another partial view? Is it good or bad practice, what problems can occur, does it require any workarounds etc?

like image 769
sparta223 Avatar asked Dec 06 '25 09:12

sparta223


1 Answers

The only problem I see is that when logic is complicated, you'll need multiple viewmodels to be passed to your main view. And you have to handle it somehow. When it comes to testing application, it may require additional efforts.

You can store these viewmodels in ViewBag, but it seems a code smell. If you don't have much logic in these views, or if they use the same viewmodel, it's absolutely fine.

If you have very complicated logic in your views, try thinking about something like Angular, ReactJS. You'll have multiple views on the client side and will be able to test your app.

like image 61
Roman Pushkin Avatar answered Dec 08 '25 00:12

Roman Pushkin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!