Tech Junkie Blog - Real World Tutorials, Happy Coding!: End-to-End ASP.NET MVC : Create an ASP.NET MVC Empty Project

Saturday, June 18, 2016

End-to-End ASP.NET MVC : Create an ASP.NET MVC Empty Project

A lot of people think that you can only create one kind of ASP.NET MVC  project, the one with the sample application.  But the reality is that you can create an Empty ASP.NET MVC, you just need to do more work.  However, it is cleaner and you can add what you need, instead of having everything in place already like the default template.  So you might run into more errors with the empty project, but I think you will learn more about MVC than if you just have the default template.  Plus it's more streamline.  I always start with an empty project on my MVC projects.  In order to follow this tutorial you must have Visual Studio 2017 installed.


Step-By-Step Instructions:
  1. Create a new project in Visual Studio call "NorthwindCafe", by clicking on File → New → Project
  2. Select Visual C# → Web → ASP.NET Web Application, in the "Name:" field type the name "NorthwindCafe", then click "OK"


 3.  On the next screen select "Empty" on the "Select a template" menu, then under "Add folders and core references for:", check the "MVC" checkbox.


 4.  Your empty ASP.NET MVC  project is created in Visual Studio 2017


5.  We are not done yet,  since this is an empty project we will get an error if we try to run the application.  Hit "Ctrl+F5" to run the application.  You will get this message



Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3056.0

The reason you are getting a 404 error is because there's no "Controller" or "View" to browse to.  Since we just created a bare bones ASP.NET MVC  project.

6.  So to get the application to run we will create a simple Controller and View in the MvcApp project.

7. Right click on the "Controller" folder and select "Add" → "Controller"



8.  On the "Add Controller" screen type "HomeController" on the "Controller name" text box and select "Empty MVC controller".  We just want to keep things simple for this blog.  Then click "Add"





9.  You see the "HomeController.cs" class being added to the "Controllers" folder

HomeController configuration

10.  Double click on the "HomeController.cs" file and you will see the following code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NorthwindCafe.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }

    }
}


11.  Right click on the "Index()" method and select "Add View"

Add View To Index method








12.   Uncheck the "Use a layout or master page" checkbox. Accept the default settings, MVC uses conventions so the view has the same name as the method name in the "HomeController.cs" file which is "Index()", then click "Add"




13.  In the "Views" folder you see that the "Home" folder has been created with the view "Index.cshtml", the .cshtml extension means that the view uses the C# syntax.


14.  Double click on the view "Index.cshtml" and type "Hello World" between the <div> tag like the markup below

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        Hello World!
    </div>
</body>
</html>

15. Press Ctrl+F5 to run the application, you will see the following.

Browse Hello World View












16.  Now that we have a working empty ASP.NET MVC project, we need add the items to the projects using NuGet.


Similar Posts:


                                                                                               Next: ASP.NET : Add jQuery Library Using NuGet
           

95 comments:

  1. Hello,

    I followed your tutorial step by step I still get The resource cannot be found.

    I don't know what seems to be the problem.

    I am using VS express 2012 but I have added the plugin to use MVC5 so I created an epmty mvc5 project

    Thanks

    ReplyDelete
  2. What step are you stuck on? I used Visual Studio 2013 the full version so the steps might be a little different.

    ReplyDelete
  3. Actually I think I was using Visual Studio Community Edition 2013 you can get it here at https://www.visualstudio.com/en-us/news/vs2013-community-vs.aspx

    ReplyDelete
  4. Hello,

    I have the same problem of Sabrine Azouz, in the step 15 when trying to run the application, get the resource cannot be found error

    ReplyDelete
  5. I had the same trouble, but it went away when I restarted Visual Studio. I'm using VS2015 community, and everything works fine. Thanks Jason, great article.

    ReplyDelete
  6. Thank you so much for writing this. I have been looking for a long time for a set of tutorials that starts without everything auto-installed, allowing you to add things as you need them so you understand what's going on. This is fantastic.

    ReplyDelete
  7. Thanks for this. It was really helpful!

    ReplyDelete
  8. Hey, I just wanted to mention that these instructions worked perfectly using Monodevelop 5.10 on a Fedora 23 box. The only deviation from these instructions that I had to do was to create a registry directory. Like so...

    sudo mkdir /etc/mono/registry
    sudo chmod uog+rw /etc/mono/registry/

    Thanks for your efforts in putting together this tutorial!

    ReplyDelete
    Replies
    1. I'm using Debian 8.x and the directory already exists.

      Thanks!

      Delete
  9. Thanks I've been looking for good tutorial that would start from scratch. Most of the books I see use MVC template..

    ReplyDelete
  10. Thank u so much. Explained in such a easy and simple way. Really helpful.

    ReplyDelete
  11. I am using vidual studio 2015.I have created mvc empty web application.
    I have created 2 webpages in aspx.also created controller for both.
    when i buld the project one page gets loaded successfully in browser.

    On click of a buuton on one page second page shuld be loaded.like anchor tag does in html.
    Can you help me with that?

    ReplyDelete
    Replies
    1. I would recommend that you remove the .aspx page. Since this is an MVC application and razor is the view template that Microsoft is pushing. It would make your life a lot easier if you stick with razor

      Delete
  12. thanks dude. I was going bonkers trying to get a simple asp.net one page mvc website running. This got me going in the right direction

    ReplyDelete
  13. Really excellent tutorial gives very in-depth picture how actually thing works sir

    ReplyDelete
  14. This comment has been removed by a blog administrator.

    ReplyDelete
  15. This comment has been removed by a blog administrator.

    ReplyDelete
  16. Very Nice blog. Really helpful information about ASP …. Please keep update some more…………

    ReplyDelete
  17. nicely explain the process to create mvc project

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. Well done, man.
    It wasn't easy to find the answer for a new developer in ASP as miself.

    ReplyDelete
  20. This comment has been removed by a blog administrator.

    ReplyDelete
  21. This comment has been removed by a blog administrator.

    ReplyDelete
  22. I am really happy to say it’s an interesting article to read. I learn new information from your article you are doing a great job. Keep it up

    Affiliate Marketing Training in Hyderabad

    Online Reputation Management Training in Hyderabad

    Email Marketing Course in Hyderabad

    E-Commerce Marketing Training in Hyderabad

    ReplyDelete
  23. Thanks for sharing. I really liked your post, keep sharing!!

    CEH Training In Hyderbad

    ReplyDelete
  24. Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
    AWS Training in Chennai
    Data Science Training in Chennai
    Python Training in Chennai

    ReplyDelete
  25. Nice post. Thanks for sharing! I want people to know just how good this information is in your article. It’s interesting content and Great work.
    Thanks & Regards,
    VRIT Professionals,
    No.1 Leading Web Designing Training Institute In Chennai.

    And also those who are looking for
    Web Designing Training Institute in Chennai
    SEO Training Institute in Chennai
    Photoshop Training Institute in Chennai
    PHP & Mysql Training Institute in Chennai
    Android Training Institute in Chennai

    ReplyDelete
  26. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.
    Data Science Training in Chennai | Best Data Science Training in Chennai
    Python Training in Chennai | Best Python Training Institutes in Chennai
    RPA Training in Chennai | Best RPA Training in Chennai
    Digital Marketing Training in Chennai | Best Digital Marketing Training in Chennai

    ReplyDelete
  27. AWS is very popular in current days among all cloud computing courses.
    Get aws training in hyderabad

    ReplyDelete
  28. I feel happy about and learning more about this topic. keep sharing your information regularly for my future reference. This content creates a new hope and inspiration with in me. Thanks for sharing article like this. the information which you have provided is better then other blog.
    Best IELTS Coaching in Dwarka sector 12

    ReplyDelete
  29. In the beginning, I would like to thank you much about this great post. Its very useful and helpful for anyone looking for tips. I like your writing style and I hope you will keep doing this good working.
    Ethical Hacking Course in Chennai
    Certified Ethical Hacking Course in Chennai
    PHP Training in Chennai
    ccna Training in Chennai
    Web Designing Course in Chennai
    ethical hacking course in chennai
    hacking course in chennai

    ReplyDelete
  30. This comment has been removed by the author.

    ReplyDelete
  31. Awesome post I am obliged for sharing this. I’m a newcomer to Dot net developer but have used wordpress for long time. I needed exact information for my new project. It is an informative article, keep sharing.
    https://www.exltech.in/dot-net-training.html

    ReplyDelete
  32. I love this post.

    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
    สมัครสมาชิกที่นี่ >>> Gclub online

    ReplyDelete
  33. Very cool!

    เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
    เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา สมัคร Gclub Royal1688
    และยังมีเกมส์สล็อตออนไลน์ 1688 slot อีกมากมายให้คุณได้ลอง
    สมัครสมาชิกที่นี่ >>> Gclub Royal1688

    ReplyDelete
  34. Really It is very useful information for us. thanks for sharing..
    AWS Training In Hyderabad

    ReplyDelete
  35. Wonderful post. Thank you for updating such an informative content.

    Best Python Training Academy in Kanchipuram

    ReplyDelete
  36. Thanks for this greatful information. all this information is very important to all the users and can be used good at all this process
    Best Tally ERP 9.0 Training Academy in Kanchipuram

    ReplyDelete
  37. Just now I read your blog, it is very helpful nd looking very nice and useful information.
    Digital Marketing Online Training
    Servicenow Online Training
    EDI Online Training

    ReplyDelete
  38. really you have posted an informative blog. it will be really helpful to many peoples. thank you for sharing this blog. so keep on sharing such kind of useful blogs.

    Best TALLY ERP 9.0 Training Academy In Kanchipuram

    ReplyDelete
  39. Your article was so impressive and informative. Its very interesting to read. Thanks for sharing,
    Best web design Training Institute in Kanchipuram

    ReplyDelete
  40. Good explanation information
    Sanjary Academy provides excellent training for Piping design course. Best Piping Design Training Institute in Hyderabad, Telangana. We have offer professional Engineering Course like Piping Design Course,QA / QC Course,document Controller course,pressure Vessel Design Course, Welding Inspector Course, Quality Management Course, #Safety officer course.
    Piping Design Course in Hyderabad ­

    ReplyDelete
  41. Bergantung pada keyakinan – jika anda mau menang dengan menggunakan mantra, maka salah satu landasan dasar yang sangat penting sekali untuk dilakukan adalah tentang bagaimana anda memiliki keyakinan yang cukup
    asikqq
    http://dewaqqq.club/
    http://sumoqq.today/
    interqq
    pionpoker
    bandar ceme
    freebet tanpa deposit
    paito warna terlengkap
    syair sgp

    ReplyDelete
  42. And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
    cloud computing courses in chennai | cloud computing training in chennai | cloud training in chennai

    ReplyDelete
  43. Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is fantastic, let alone the content!

    3d animation Company
    Best Chatbot Development Company
    Mobile app development in Coimbatore

    ReplyDelete
  44. Excellent Blog. I really want to admire the quality of this post. I like the way of your presentation of ideas, views and valuable content. No doubt you are doing great work. I’ll be waiting for your next post. Thanks .Keep it up! Kindly visit us @Luxury Boxes
    Premium Packaging
    Luxury Candles Box
    Earphone Packaging Box
    Wireless Headphone Box
    Innovative Packaging Boxes
    Wedding gift box
    Leather Bag Packaging Box
    Cosmetics Packaging Box
    Luxury Chocolate Boxes

    ReplyDelete
  45. You blog post is just completely quality and informative. Many new facts and information which I have not heard about before. Keep sharing more blog posts.

    ReactJS Online Training

    ReplyDelete