C
C#

help

βœ… 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">
<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");
}
[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!
AAngius11/25/2022
It takes the class whose method handled the GET request to display this form Or rather, it POSTs to the same URL 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);
}
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 πŸ™‚
AAngius11/25/2022
Yep, exactly
AAccord11/28/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. Closed!

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Difference between using { get; set; } and notI'm pretty new to C# (experienced in C++ and Python), and I was wondering if someone could clarify t❔ DbUpdateConcurrencyExceptionGetting `DbUpdateConcurrencyException` on Save❔ Navigation properties internals. EFCoreHow are they implemented internally? What if I select related entity Id to 3, and the related entityβœ… Mapping an Identity user to an instance of an EF core model IDAny suggestions on how to make an identity user have a model ID? I need to do this so I can have a c❔ Automapper map Id to EntityI receive the following DTO (request) BookDTO{ int Id, int AuthorId } I want the mapper to map Autβœ… HashSet property with List backing fieldPosting here instead of in #database because it's not really related to db-specific stuff. For reas❔ Cannot open output file for writingHi all, trying to build my project with Visual Studio. Whenever I do I get an error from CSC statingβœ… Passing Multiple Parameters Through A ButtonI would like to call this method: ```csharp public async Task<IActionResult> OnPostAsync(int? id, s❔ SQL Server | Count How Much Installment Paid and Left**#ask #query # sql server** hi i have a question, last week my teacher give a task to select data f❔ Is there a way to improve this code Performance ?have a collection of items that haveΒ `_id`Β andΒ `serialNumbers`Β (an array) fields (and other fields aβœ… EF Core, All models into one collectionI would like to make a single collection of all models in the database. What is a good approach for βœ… Incorrect math`(3 / 4) * 100` returns 0, when it should return 75. Why is this?❔ Antiforgery token validation in API'sAntiforgery tokens are for preventing cross-site request forgery. Does that mean all sensitive API'sβœ… Naming functions using stringsIn Kotlin, it is possible to name function as strings surrounded by ` `. Thus we can have white spacβœ… Check a box on a websiteHow can I check a box on a local website using c#? Havent found anything on googleIs it possible to create a program that just goes on a specific url,logs in and then activates smth?I wanted to create smth quick to enable/disable the routers 5ghz option.. it runs on a local/private