简体   繁体   中英

Adding mvc project to asp.net project

I'm currently in the process of trying to set up my final year project to begin writing but I'm struggling to do so.

Basically, I have an existing project that uses asp.net and need to add a new MVC project where they can run together. The asp.net project will handle the login but with have a simple link to the mvc project. The issue is I can't get the from the asp.net project to the MVC one to work correctly.

I don't want MVC inside the asp.net project but in its own project inside the same solution. I've looked all over for some kind of answer but all I can find is how to add MVC inside an asp.net project.

I can do this with two asp.net projects but am as of yet unable to get an asp.net project working with a new mvc project.

Any help or advice would be appreciated.

Thanks

It's really difficult to understand your exact problem, just on the basis of info provided, apologies for not asking for clarification in comments, as i can't post comments on question requiring a reputation of 50, which at the time of writing i don't have.

@Phil has answered correctly as to how to add a new project to solution, but your comment says that you are not able to reference to MVC project through links in existing project, something like

href="~/MVC/somecontroller/someaction/someparameters"

If that is something you're after, then the actual logic behind this working is that those two projects have different paths and you'll require to setup virtual directories on same path.

You haven't mention that you're using ASP.NET 4.5+ MVC 5 or ASP.NET 5 MVC 6 as procedures are different. For the help of future readers i am posting for both platforms in Visual Studio. Screenshots are from Visual Studio 2015 Enterprise, but it's the same across most(if not all) versions after Visual Studio 2012

ASP.NET 4.5+ MVC 5

  1. Double Click on Properties on existing project which will be root project
  2. Click on Tab named "Web"
  3. You'll find the Input Box for Project URL
  4. Copy the URL
  5. Repeat Steps 1-3 for MVC project
  6. Paste the Copied URL and append MVC at the end and click on Create Virtual Directory

在此处输入图片说明

ASP.NET 5 MVC 6

  1. Repeat Steps 1-4 for existing project
  2. Open Properties for ASP.NET 5 Project
  3. Click on Tab named Debug
  4. You'll find the Input Box for App URL under Web Server Settings
  5. Paste the copied URL and append MVC to it

在此处输入图片说明

Hope that helps

For Visual Studio 2013:

  1. Show Solution Explorer
  2. Right Click on your Solution (DemoWebSol in screen grab)
  3. Select Add > New Project ...
  4. Proceed with adding the new project as you would normally

在此处输入图片说明

Visual Studio manages different projects are part of the same solution. I'm not sure how other versions of VS do this but it would be a very similar approach.

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