Some clarification on how the controller handles an HTTP request in C #?

I am completely new in C # and I do not really get into MVC (I came with Java)

I have the following doubts:

I have a controller package \ folder (I don’t know the name propper in Visual Studio) with the name Controllers , which contains the control elements that process the incoming HTTP request.

So, inside this folder there is a class TestController.cs , which looks something like this:

namespace MyWebApplication.Controllers
{
    public class AndreaController : MyBaseController
    {
        // Manager che effettua la connessione ed ottiene i dati da visualizzare nella view:
        private MaliciousCodeManager manager = new MaliciousCodeManager("DefaultConnection");


        //
        // GET: /Test/

        /* Method that handle the HTTP REQUEST toward /Test/index
         * 
         */
        public ActionResult Index(DataModel.MaliciousCode.SearchMalicious model)
        {

            Debug.WriteLine("*** FILTRI DI RICERCA ***");
            ...................................................
            ...................................................
            ...................................................
            DO SOME STUFF
            ...................................................
            ...................................................
            ...................................................
        }
}

So, it seems to me that this controller processes the request along the path / Test /

and therefore, the Index () method processes the request at / Test / index . I think this is pretty clear to me.

, Index:

public ActionResult Index(DataModel.MaliciousCode.SearchMalicious model)

, DataModel.MaliciousCode.SearchMalicious model.

, , Index() HTTP- SearchMalicious

, : ? ? ?

Tnx Andrea

+4
3

, ... , . , , , .

, , . , , , , , , .

, , , . , - , , , .

+2

, . MVC, . , . , , global.asax.

. , , . / , .

+2

. , - , . , Index http://example.org/Andrea http://example.org/Andrea/Index. Index - .

( App_Start/RouteConfig.cs Global.asax.cs), .

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

ASP.NET MVC, URL- , . - , URL . ActionResult. - , .

ASP.NET URL-, . : ASP.NET MVC id URL- . , http://example.org/Home/Index/3, 3, .

public class HomeController : MyBaseController
{
    public ActionResult Index(int id)
    {
        //id is 3
    }
}

(, ) , . SearchMalicious type:

public class SearchMalicious 
{
    public string Keyword { get; set; }
    public string OrderBy { get; set; }
}

When you run the http://example.org/Andrea?keyword=abc&orderby=def query , the model binding will instantiate SearchMaliciousand populate these properties using the querystring values. Also, this model can be populated from the form fields in the POST request.

+1
source

Source: https://habr.com/ru/post/1531398/


All Articles