The problem:
Two attributes are needed for a Controller. However, one of them (datetime) goes as null.
Routing:
A new routing was incorporated so the Controller could receive two attributes:
app.UseMvc(routes => { routes.MapRoute("RequestHistorial","HechosLiquidadors/Details/{id:int}/{date:datetime}", defaults: new { controller = "HechosLiquidadors", action = "Details" }); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); });
The datetime parameter doesn't have a format restriction or anything.
How the data is sent
This is the view that sends the parameters:
<table class="table table-bordered table-hover table-striped" id="LiquidacionesList"><thead><tr> {...}<th>Resultados</th></tr></thead><tbody> @foreach (var item in Model) {<tr> {...}<td><div class="btn-group"><a asp-action="Details" asp-route-id="@item.StoreID" asp-route-date="@item.FechaLFinLiq" class="btn btn-default">Consultar</a></div></td></tr>
This table is constructed with a foreach which iterates thru each element of the model sent to the view and the button at the end receives the attributes needed and usingasp-route-id/date these are sent. Note: The table is constructed just fine. All the desired data is shown.
The result
When the button is clicked this is the web address that is shown:
http://localhost:60288/HechosLiquidadors/Details/13?date=21%2F11%2F2017%200%3A00%3A00
For this part: date=21%2F11%2F2017%200%3A00%3A00 I assume the data is going to the controller. However, when I execute the following code in the Controller:
public async Task<IActionResult> Details(int? id, DateTime date) { return Content(id + "/" + date); }
The result is: 11 / 01/01/0001 0:00:00
I believe is a problem with formatting the date that is passing to the Controller? I've been looking for an answer with no luck.
Thanks in advance.
UPDATE:
It seems like the problems is in how the Get method takes this date. It looks like the Get method expects another format that the one is given and thus it declares the date as null.
Will keep updating.