Can ASP.Net MVC Views (*.aspx) be reused in multiple ASP.net MVC projects?

前端 未结 2 1636
清歌不尽
清歌不尽 2021-02-06 02:47

I would like to reuse *.aspx files in multiple ASP.Net MVC projects. Is this possible?

EDIT: Anthony\'s suggestion of using version control system to share common files

2条回答
  •  孤城傲影
    2021-02-06 03:31

    One idea you could try would be to:

    1. Create a project (class library) for your shared Views
    2. Add and set any *.aspx markup pages to Embedded Resources in the Properties pane
    3. Add a class "EmbeddedViewResult" that inherits from ActionResult - this would contain logic to ensure the embedded .aspx files are extracted and available on disk when called at the end of a controller action.

    So in the projects that you wanted to use the shared Views, the controller actions could return something like

    public ActionResult Shared()
    {
        return new EmbeddedViewResult("SharedLib.SharedPage");
    }
    

    I've done something similar with WebForms pages, so it should be possible.

提交回复
热议问题