You doubt Asp.Net MVC

Asked

Viewed 103 times

2

The structure is View -> Controller -> Model ? I work with three layers but it’s not MVC. What does that stretch mean ?

@{
    ViewBag.Title = "Index";
}

What is Actionresult ? You don’t have Page_load ? I’m lost. Can someone help me ?

  • What exactly is your doubt?

  • Man, everything rsrs .. I’m starting to move now, I move with Asp.net, 3 layers and for me everything is different.

  • If the post helped you, mark your response

1 answer

5


ASP.NET MVC has a very different concept than you are used to with webforms. There is no page concept .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 that 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 in the same).

We are called the Controller Home Index method.

This method in turn returns a View.

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

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 display this content on your page (index.cshtml)

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

And

@{
  ViewBag.Title = "Index";
}

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>
  • I understood your answer, but the doubts are many rs. Thank you.

  • I see here also the kind of methods are "Actionresult" what is this ?

  • Actionresult can be a View (an html) or a Json object, or a Javascript, a Stream... the View() method returns a Viewresult, if changing to Json(object) it in place of an html would return a Json object

Browser other questions tagged

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