c# - Mapster Adpat not working -
i`m trying make select in form-control.
<div class="form-row form-row-wide"> <div class="col-sm-3"> <select asp-for="estadoid" class="form-control input-text" required="required" placeholder="estado"></select> <span asp-validation-for="estadoid" class="text-danger"></span> </div> <div class="col-sm-9"> <select asp-for="cidadeid" class="form-control input-text" required></select> <span asp-validation-for="cidadeid" class="text-danger"></span> </div> </div>
but adapt not getting element`s. controller.
public async task<jsonresult> get(select2request param) { try { var pagedresults = await _service.getallbypageasync(w => w.nome.like(param.q), 20, param.page); var result = pagedresults.data.adapt<list<stateviewmodel>>().adapt<list<select2response>>(); return json(result); } catch (exception e) { return new jsonresult(badrequest(e)); } }
the problem is, after pass adpat elements r null. mapping.
public class statemapping : iregister { public void register(typeadapterconfig config) { config.newconfig<stateviewmodel, select2response>() .map(p => p.id, s => s.estadoid) .map(p => p.text, s => s.nome); } }
how should make work?
at startup startup place following code :
using mapster; //reference package namespace yourapplication { public class startup { public startup(ihostingenvironment env) { //his previous codes ... //place code typeadapterconfig.globalsettings.scan(assembly.getentryassembly()); } } }
Comments
Post a Comment