No constructor without parameters has been defined for this object

Asked

Viewed 93 times

2

I am creating an endpoint in an api and when a method request is made the API returns the error "No constructor without parameters has been defined for this object." even though a builder has been created for it

using Backend.Business;
using Backend.Model;
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;

    namespace FrontEnd.Controllers
    {
        public class RepliValParamEspfController : Controller
        {
            public OC oc;
            public JavaScriptSerializer serializer;
            public RepliValParamEspfBusiness call;

            public RepliValParamEspfController()
            {
                    this.oc = new OC();
                    this.serializer = new JavaScriptSerializer();
                    this.call = new RepliValParamEspfBusiness();
            }
            public object Gravar(RetornaValoresPadroesItens Objs)
            {
                try
                {

                    if (Objs.FilialDestino == null)
                    {
                        this.oc.dados = "Necessario informar Filial Destino!";
                        this.oc.status = true;
                        this.oc.mensagem = "Necessario informar Filial Destino!";
                    }
                    if (Objs.FilialDestino.Equals(String.Empty))
                    {
                        this.oc.dados = "Necessario informar Filial Destino!";
                        this.oc.status = true;
                        this.oc.mensagem = "Necessario informar Filial Destino!";
                    }
                    if (Objs.FilialOrigem == null)
                    {
                        this.oc.dados = "Necessario informar Filial Origem!";
                        this.oc.status = true;
                        this.oc.mensagem = "Necessario informar Filial Origem!";
                    }
                    if (Objs.FilialOrigem.Equals(String.Empty))
                    {
                        this.oc.dados = "Necessario informar Filial Origem!";
                        this.oc.status = true;
                        this.oc.mensagem = "Necessario informar Filial Origem!";
                    }
                    if (Objs.Cpf.Equals(String.Empty))
                    {
                        this.oc.dados = "Necessario informar CPF!";
                        this.oc.status = true;
                        this.oc.mensagem = "Necessario informar CPF!";
                    }
                    if (Objs.Autor.Equals(String.Empty))
                    {
                        this.oc.dados = "Necessario informar Autor!";
                        this.oc.status = true;
                        this.oc.mensagem = "Necessario informar Autor!";
                    }

                    if (this.oc.mensagem == String.Empty)
                    {
                        var response = this.call.Gravar(Objs);
                        this.oc.dados = response;
                        this.oc.status = true;
                        this.oc.mensagem = "Atualizado com sucesso!";
                    }
                }
                catch (Exception e)
                {
                    this.oc.status = false;
                    this.oc.mensagem = e.Message;
                }
                return serializer.Serialize(this.oc);
            }
        }
    }
  • Where the error comes?

  • it passes through the public Replivalparamespfcontroller() but does not fall into the Record method

  • it returns in Postman after passing the constructor the message of "No constructor without parâmeters has been set for this object"

2 answers

2

Go to your OC Entity and put a guy like that:

    public class OC{
...
           public OC(){}
...
    }
  • 1

    I was able to solve the error inside the Retvalue() { }

2

I was able to solve the error inside the Retvalue I created the following:

   public RetornaValoresPadroesItens() { 

   }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.