I´m usin VS 2019, .net core 3.1. I´m trying to create a crud using automapper. On the create action am getting an error, i´ve tried several forms but none seems to work
Error:
The entity type 'CustomerCountriesDto' was not found. Ensure that the entity type has been added to the model.
On the view
@model ManufacturaMVC.Models.CustomerCountries
Controller
private readonly ApplicationDbContext _context;
private readonly IMapper _mapper;
public CustomerCountriesController(ApplicationDbContext context, IMapper mapper)
{
_context = context;
_mapper = mapper;
}
public async Task<IActionResult> Create([Bind("CustomerCountry")] CustomerCountries customerCountries)
{
if (ModelState.IsValid)
{
//var model = _mapper.Map<CustomerCountriesDto>(customerCountries);
var user = _mapper.Map<CustomerCountries, CustomerCountriesDto>(customerCountries);
_context.Add(user);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
Error
Missing type map configuration or unsupported mapping.
Controller
public async Task<IActionResult> Create([Bind("CustomerCountryDto")] CustomerCountriesDto customerCountries)
{
if (ModelState.IsValid)
{
var model = _mapper.Map<CustomerCountriesDto>(customerCountries);
var user = _mapper.Map<CustomerCountriesDto, CustomerCountries>(customerCountries);
_context.Add(user);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(customerCountries);
}
Member
1 Points
4 Posts
Error when creating a record with Automapper
Jul 08, 2020 07:59 PM|hernandez0808|LINK
I´m usin VS 2019, .net core 3.1. I´m trying to create a crud using automapper. On the create action am getting an error, i´ve tried several forms but none seems to work
Error:
On the view
Controller
Error
Controller
View
Error
View
Controller
Models
Can someone please tell me how is the correct way or, what is wrong?
</div> </div>Contributor
4983 Points
4265 Posts
Re: Error when creating a record with Automapper
Jul 08, 2020 09:25 PM|DA924|LINK
Automapper has a forum.
https://groups.google.com/forum/#!forum/automapper-users