简体   繁体   中英

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?

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.

您应该将您的视图嵌入到Project.Common dll中,详细说明可以在https://visualstudiogallery.msdn.microsoft.com/f28290ce-d987-4f91-b034-707031e10ce6上找到。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM