Questions regarding Asp.Net MVC [closed]

2

The structure is View - > Controller - > Model I work with 3 layers but it is not MVC. What does this passage mean?

   
@{
    ViewBag.Title = "Index";
}

What is ActionResult? Do not have Page_Load? I'm lost. Can anyone help me?

    
asked by anonymous 18.06.2015 / 19:55

1 answer

5

ASP.NET MVC has a very different concept than what you are accustomed to with webforms. There is no concept of page .aspx , that is, a URL no longer refers to a particular file on the site.

When you create your first project. Visual Studio creates for you a HomeController , a class inherited from Controller .

This class has a method called Index which returns a ActionView .

Home / Index are the controller and default method that are invoked if you do not request anything different ( //localhost:60253/Home/Index , //localhost:60253/Home , //localhost:60253 give it anyway).

We are called the Index method of Controller Home.

This method in turn returns a View.

By default, the view is index.cshtml of the /Views/Home folder

ViewBag is a collection of values that can be passed from the controller to the View.

Example:

    public ActionResult Index()
    {
        ViewBag.Mensagem = "Olá Mundo";
        return View();
    }

Allows you to show this content on your page (index.cshtml)

<body>
  Mensagem: @ViewBag.Mensagem
</body>

E

@{
  ViewBag.Title = "Index";
}

I would change the value of the ViewBag Title attribute to "Index", which might change the title of your page if your cshtml had this code:

<title>@ViewBag.Title</title>
    
18.06.2015 / 20:12
______ azszpr69569 ___

%pre% %pre%
    
___