Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
How to POST javascript object, javascript object list and file list to asp.net core controller

I want to pass all data to controller after clicking button.

 var data = new FormData();

Here is my javascript object

var info = {};
info.CorporateName = $("input[name*='CorporateName']").val();
info.CorporatePhone1 = $("input[name*='CorporatePhone1']").val();
info.CorporatePhone2 = $("input[name*='CorporatePhone2']").val();
info.CorporateEmail = $("input[name*='CorporateEmail']").val();

I can reach these datas from the controller with code below

$.each(info, function (key, input) {
            data.append(key, input);
        });

Here is my file list. I can reach these files from the controller with code below

var allfiles = $(".required-files");

for (var i = 0; i < allfiles.length; i++)
{
  var files = allfiles[i].files;
  data.append('files', files[0]);
}

Here is my packages cookie. I can't reach package list from the controller

var packageList = $.parseJSON($.cookie("packageList"));
 data.append('packageList',JSON.stringify(packageList));

I can post files, my info object but I can't post cookie list

Here is my controller

[HttpPost]
public async Task<IActionResult> create(IEnumerable<IFormFile> files, List<PostServiceDto> packageList, ModelDto Model)
        {
          // files = not null, Model not null, but packageList = null

            var model = Request.Form;

            return View();
        }

My package model

 public class PostServiceDto
    {
        public string Type { get; set; }
        public string Name { get; set; }
        public string Price { get; set; }
        public string Id { get; set; }
        public string Count { get; set; }
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I couln't take the list it with parameter but I solved it getting json object form request body.

the value returned from request ={\"Type\":\"3\",\"Name\":\"dfsfsdfs\",\"Price\":\"44,00\",\"Id\":\"2\",\"Count\":1},{\"Type\":\"3\",\"Name\":\"Yeni Paket\",\"Price\":\"49,90\",\"Id\":\"1\",\"Count\":1} Solution

foreach (var item in Request.Form.Keys)
            {
                if(item == "packageList")
                {
                    clearObject(Request.Form[item]);


                }
            }



public List<PostServiceDto> clearObject(string value)
        {
            List<PostServiceDto> postServices = new List<PostServiceDto>();
            List<PostServiceDto> myDeserializedObjList =
                (List<PostServiceDto>)Newtonsoft.Json.JsonConvert.DeserializeObject(value, typeof(List<PostServiceDto>));
            return myDeserializedObjList;

        }

code source : [https://www.codeproject.com/Tips/79435/Deserialize-JSON-with-C]

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda