0
I am trying to return a list of a "Plan" Template that has a list of "Expenses", returning only the plan list works, but when added to return the spending list of a javascript error.
"Failed to load Resource: net::ERR_SPDY_PROTOCOL_ERROR"
"Uncaught (in Promise) Typeerror: Failed to fetch"
Controller
[HttpPost] public IEnumerable<Plano> GetPlanos() { return db.GetPlanos() .AsEnumerable(); }
Modelo dos Gastos
[DataContract] public class Gastos { [DataMember] public long Id { get; set; } [DataMember] public string Descricao { get; set; } [DataMember] public TipoFrequencia Frequencia { get; set; } [DataMember] public TipoGasto Tipo { get; set; } [DataMember] public DateTime? Data { get; set; } [DataMember] public double Valor { get; set; } [DataMember] public Plano Planos { get; set; } }
Flat Model
[DataContract] public class Plano { [DataMember] public long Id { get; set; } [DataMember] public List<Gasto> Gasto { get; set; } [DataMember] public int Moradores { get; set; } }
Javascript call
componentDidMount() { fetch('Plano/GetPlanos', { method: 'POST' }) .then(response => response.json()) .then(data => { console.log(data); this.setState({ lista: data, loading: false }); }); }
Query in the database
public IQueryable<Plano> GetPlanos() { return _contexto.Planos .Include(p => p.Gastos); }
Not even this console.log runs, the error happens before, if I take [Datamember] out of the spending list works.
Debugging on Asp.net da to see that it’s all right he picks up the data all right, only at the time to return to the javascript that the problem.
Put that part in your question:
db.GetPlanos()
what this method does?– novic
ready, I made an adjustment in the controller that was wrong tbm, but the error remains the same
– Leonardo Bressan
because you’re using the verb
post
to get a get? o. The– Caio Felipe Pereira
anyway, the way you describe the problem, it seems to me that it is in the API and not in React...
– Caio Felipe Pereira