✅ MS webshop example

BObig OOF11/25/2022
Hello,

Im trying to understand the different parts of a webshop example from Microsoft.

I have a question about routing, the view looks like this(see attached).

My question is regarding this line:
 <form asp-action="OrderProcess" id="orderForm+@item.OrderNumber" method="post">

I find the function OrderProcess in OrderManagementController and it takes a POST-request:
    [HttpPost]
    public async Task<IActionResult> OrderProcess(string orderId, string actionCode)
    {
        if (OrderProcessAction.Ship.Code == actionCode)
        {
            await _orderSvc.ShipOrder(orderId);
        }

        return RedirectToAction("Index");
    }


To my question - how does it know in which cs file the function is located? I cant see any "connection" in the view. I cant imagine that it looks into every class to see wheter it has a OrderProcess and takes a POST-argument, but maybe im wrong? 🙂

Thanks in advance!
Image
AAngius11/25/2022
It takes the class whose method handled the GET request to display this form
AAngius11/25/2022
Or rather, it POSTs to the same URL
AAngius11/25/2022
So whichever controller handles /my/cool/form, will handle the POST request. And which action method will do it specifically, is denoted by asp-action
BObig OOF11/25/2022
@ZZZZZZZZZZZZZZZZZZZZZZZZZ Okey, thanks!

A follow-up question, this is the start of the program:
    public async Task<IActionResult> Index(int? BrandFilterApplied, int? TypesFilterApplied, int? page, [FromQuery] string errorMsg)
    {
        var itemsPage = 9;
        var catalog = await _catalogSvc.GetCatalogItems(page ?? 0, itemsPage, BrandFilterApplied, TypesFilterApplied);
        var vm = new IndexViewModel()
        {
            CatalogItems = catalog.Data,
            Brands = await _catalogSvc.GetBrands(),
            Types = await _catalogSvc.GetTypes(),
            BrandFilterApplied = BrandFilterApplied ?? 0,
            TypesFilterApplied = TypesFilterApplied ?? 0,
            PaginationInfo = new PaginationInfo()
            {
                ActualPage = page ?? 0,
                ItemsPerPage = catalog.Data.Count,
                TotalItems = catalog.Count,
                TotalPages = (int)Math.Ceiling(((decimal)catalog.Count / itemsPage))
            }
        };

        vm.PaginationInfo.Next = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
        vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";

        ViewBag.BasketInoperativeMsg = errorMsg;

        return View(vm);
    }

It just returns a view but dosent specify which - am i correct by thinking it is written "under the hood" by the mapping structure? CatalogController return a view named index -> the program looks for a catalog-folder under views -> returns index view.

Attatched an image of the folder structure 🙂
Image
AAngius11/25/2022
Yep, exactly
AAccord11/26/2022
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
AAccord11/28/2022
Closed!