Hola uso Visual Studio 2019 con .net core 3.1, en la acción Create de mi controlador noto que no puedo llegar a la parte Post, pero si le quito el ValidateAntiForgeryToken, sí... algo pasa
Controlador
public IActionResult Create()
{
ViewData["IdCustomerCountry"] = new SelectList(_context.CustomerCountries, "CustomerCountryName", "CustomerCountryName");
return View();
}
// POST: CustomerRegions/Create
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("IdCustomerRegion,CustomerRegionName,IdCustomerCountry")] CustomerCountryRegionVM customerCountryRegionVM)
//public async Task<IActionResult> Create(CustomerCountryRegionVM customerCountryRegionVM)
{
if (ModelState.IsValid)
{
//var region = _mapper.Map<CustomerRegionsDto, CustomerCountryRegionVM>(customerRegionsDto);
_context.Add(customerCountryRegionVM);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["IdCustomerCountry"] = new SelectList(_context.CustomerCountries, "CustomerCountryName", "CustomerCountryName");
return View(customerCountryRegionVM);
}
Vista
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="CustomerRegionName" class="control-label"></label>
<input asp-for="CustomerRegionName" class="form-control" />
<span asp-validation-for="CustomerRegionName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="IdCustomerCountry" class="control-label"></label>
<select asp-for="IdCustomerCountry" class="form-control" asp-items="ViewBag.IdCustomerCountry"></select>
<!--Object reference not set to an instance of an object.'-->
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>