Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share PartialView between projects in a solution?

I am developing 2 MVC5 websites. They run seperately, but actually related to each other (1 Admin site, and 1 User site). In both site, I have to render a graphical board using HTML table. I am using PartialView with a Model to render it.

Currently, this is my solution structure:

  • Project.Common (A class library project, contain the model)

  • Project.Admin (MVC5 project for the Admin site), refering to Project.Common.

  • Project.User (MVC5 project for User site), refering to Project.Common.

To render the graphical board, I will use BoardData class from Project.Common, which is ok. But with current solution structure, I have to create 2 PartialView in each MVC5 project, which may be hard to maintain later.

Please suggest a good solution for reusing the PartialView. I already know I can write Helper, but that way, I have to write HTML code inside C# code, which is not very good. Is there any way to do this within Razor View?

like image 555
Luke Vo Avatar asked Aug 13 '26 19:08

Luke Vo


1 Answers

One of the options you can use is add a link to a file. In this case keep your Partial view in just single project and in second project use Add -> Existing Item, select your partial view from the first project and click on a small down arrow next to the Add button and choose Add as Link. More info can be found on MSDN, see section Add an existing item as a link.

In this case you will have a partial view only in one project and any changes to it will automatically be applied to other project as well.

like image 128
dotnetom Avatar answered Aug 15 '26 09:08

dotnetom



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!