I’m having a strange issue, I have a populated datatable and I’m trying to pass the StoreLicenseId to a method in my controller but the parameter in my method is always null. The StoreLicenseId is in my datatable. Everything looks correct but I just can’t get it to work.
View
<form method="post">
<input class="btn btn-outline-info btn-1" type="submit" value="Terminal" asp-controller="Terminal" asp-action="TerminalInfo" asp-route-id="@item.StoreLicenseId">
</form>
Controller
public IActionResult TerminalInfo(string storeLicenseId)
{
if (_context.StoreLicenses == null)
{
return NotFound();
}
var terminalModel = _context.StoreLicenses.FindAsync(storeLicenseId);
if (terminalModel == null)
{
return NotFound();
}
return View(terminalModel);
}
2
Answers
You should set your asp-route parameter to the same name of the parameter expected by the controller action, so change this
to
or change the name in the controller action to be simply id
1.Add input a name attribute
2.remove route id
OR:
Use asp-for