Want to use MVC in SharePoint 2019 Project

Sachin Soni 21 Reputation points
2021-08-07T15:22:36.437+00:00

Dear Experts,

We want to add razor page/cshtml file to our custom SharePoint 2019 project, but not able to find MVC template to our existing solution, Is there any way to add cshtml file to our existing solution

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,503 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,027 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,619 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,061 Reputation points
    2021-08-07T16:09:17.337+00:00

    Assuming this is an SharePoint app (external website) you just add the nuget package update the web.config. See this thread

    https://stackoverflow.com/questions/27553305/how-to-enable-mvc-in-a-webforms-project

    Note: if this is a SharePoint hosted addin, then mvc is not supported.

    0 comments No comments

  2. Sachin Soni 21 Reputation points
    2021-08-08T06:37:46.657+00:00

    Hello @Bruce (SqlWork.com) ,

    Many thanks for suggestion, but I don't want to create provider hosted have. we have SharePoint 2019 Project. So can we use above thread for SharePoint 2019 project as well?

    0 comments No comments

  3. Bruce (SqlWork.com) 66,061 Reputation points
    2021-08-08T17:33:11.603+00:00

    What type of SharePoint project is it?

    SharePoint hosted addins are written in JavaScript, and have no server components, they just make Ajax calls, either to SharePoint via the api/rest, or to another website via CORS.

    A SharePoint feature project (only supported for onprem and discouraged by MS) only supports webforms.

    0 comments No comments

  4. MichaelHan-MSFT 18,036 Reputation points
    2021-08-09T02:55:16.477+00:00

    Hi @Sachin Soni

    As @Bruce (SqlWork.com) said, we can only use MVC in Provider-hosted sharepoint app.

    Otherwise, you have to bulid your own MVC app for sharepoint: https://www.youtube.com/watch?v=0PcQCROtxSo


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.