2

I`m trying to make a 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 my Adapt is not getting the element`s. This is my 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 for Adpat the elements r null. This is my 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 i make it for work?

2
  • 1
    You referenced startup TypeAdaptConfig on Startup ? Sep 22, 2016 at 18:02
  • Nope. How i add it? Sep 22, 2016 at 18:06

1 Answer 1

3

At startup Startup place the following code :

using Mapster; //Reference your package


namespace YourApplication
{
    public class Startup
    {
        public Startup(IHostingEnvironment env)
        {
           //His previous codes ...

           //Place this code
            TypeAdapterConfig.GlobalSettings.Scan(Assembly.GetEntryAssembly());
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.