How to start on MVC5 ASP.NET?

Asked

Viewed 613 times

3

Hello! About a month ago I started to venture around the world of C# and then I started to study Framework .Net. Soon after I started to study ASP.NET due to the need in my company. Today I use Visual Studio 2013 to create Web Apps with the MVC standard, of which I have worked for years in PHP.

Visual Studio creates all directories, Urls routes, and other configuration files, this is great. But I’d really like to build at least one . NET application on the MVC 5 standard once, to really know how the Framework works. Someone would have some book tip, website, functions that I would have to start studying from?

For example, in C code and other languages the application starts with void main. In Asp.net how the configuration works to boot the application. And how do I file Routes, anyway. Basically how I make the application work.

I know that in a production environment I would not create at hand, but as a programmer I think it’s important to know how things work in back-end, it’s not magic!

Thanks in advance.

  • Your question is wide, try to make it more specific, stackoverflow works different from a forum can see the differences in tour see this one link has tips on how to elaborate a question and welcome the.

  • 2

    So Raniery. First access the official website of Asp.net mvc. This link has several tutorials on the technology, and from a basic to a little deeper. Another reference is the site of k19 and Caelum is also a reference source. But the purpose of Sopt is to help with codes made, look at these links, try and come back here to help in some error. =]

  • The book "Programming with ASP.NET MVC" by Alfredo Lotar is very good for those who are starting, I’ve learned a lot. I’m not good, because I started reading a little while ago, but the book teaches the basic functions.

  • Start with the basics: The correct name is Asp.Net MVC http://www.asp.net/mvc/overview/getting-started/introduction/getting-started

1 answer

4

Start with this answer. I’ll start from her to continue.

The basic structure of an ASP.MET MVC Project

I created my project, I can connect it to a base of SQL Server Express, and I have something very similar to that:

Solution Explorer

  • App_data: Directory that stores local databases such as Localdb;
  • App_start: Classes invoked to start the application;
  • Content: Files that are usually part of the presentation, such as images and style sheets (CSS);
  • Controllers: Application controllers. Organize requests made to the system and harmonize data entities (Models);
  • fonts: Font directory;
  • Migrations: Directory that stores incremental database migrations. It is usually used with the Entity Framework, which is installed by default in the ASP.NET MVC project;
  • Models: The description of the data entities and the relationships between them. Within a DDD concept, would be the domain of application;
  • Scripts: Directory for presentation programming. Usually stores Javascript files;
  • Views: Presentation layer directories and files. Not necessarily HTML, but by default, it is. Views are written using the notation Razor.

The "Hello, World" (or equivalent) in the MVC5

How I chose the option of ASP.NET Identity, 3 Controllers are created:

  • AccountController.cs;
  • HomeController.cs;
  • ManageController.cs;

What is always created is the HomeController.cs. He usually comes like this:

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

namespace Teste.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}

The method Index would be the closest to a "Hello, World" that we can have. When starting the site, is the first request that the system meets. Try to run and put one breakpoint in the return View() to confirm this.

Ciclo Básico

In the case of Index, who has one instruction only:

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

We ask that one be returned View without giving anything to her. As we do not inform her name, the MVC will search in Views/Home by a file called Index.cshtml. If not, you will look for other extensions whose name begins with Index and then you’ll look for Index inside Views/Shared.

In fact, it is in Views/Shared that remains the layout system main, ready login screens and a standard screen of errors.

Note that the method returns a ActionResult. ActionResult can be many things:

  • One View;
  • A redirect to another Action;
  • A file;
  • An answer to raw requisition;
  • A JSON;
  • AN XML;
  • etc., etc., etc..

I will not go into detail about this so as not to overstate the question.

Viewbag

Note that in the other methods we have the use of ViewBag:

public ActionResult About()
{
    ViewBag.Message = "Your application description page.";

    return View();
}

ViewBag is an auxiliary dynamic object to fill the View with some useful information. Should not be used for persistent information. Excellent for messaging, useful identifiers and small controls. Never should be used for complex business rules.

And now?

We have several questions that can serve as next steps in your learning. We have the ASP.NET MVC website with its tutorials. The tag has an internal Wiki with more information and material for study. Need more, can open a question or join the chat and take your question with us.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.