Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

342
Visualizações
MVC - How can I use a javascript variable as an index in @Model

How can I pass a variable in a for loop in javascript to the model field?

I need to dynamically create a graph based on the selected sheet. I need to loop these graphs, but I have no idea how I can use the variable:let i in my model as an INDEX

info: The undefined functions used are for creating a graph and work correctly if I follow the syntax of the passed variables

window.onload = function () {
for (let i = 0; i < @Model.CanvasData.Count(); i++) {
var lineData = CreateLineData(@Html.Raw(Model.CanvasData[INDEX].SerializedX), '@Model.CanvasData[INDEX].CanvasName', '#00a4a4AD', '#00a4a4A1', '#00a4a436', 0.5, true);

 LineCanvas(@Html.Raw(Model.CanvasData[INDEX].SerializedY), [lineData], '@Model.CanvasData[INDEX].CanvasName', "test", false);
}
}

I also tried the ajax function, where I would return the finished data, but there I have even more problems ... for example, I do not know how to replace the entire notation @Html.Raw(SerializedVariableData) with a variable in javascript ready to pass chartjs data

This is the result of the graph if I use the index directly @Html.Raw(Model.CanvasData[0].SerializedX) enter image description here

I'm a beginner and I've been fighting for a long time, please help

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda