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

262
Visualizações
How to pass HttpPostedFileBase from JavaScript as model instead of FormData

Is it possible to pass the form data with out using FormData by using the JavaScript Model. As my form has many controls I would like to go with Model approach instead of FormData.

Is there a way to pass selected files to controller with out using HttpPostedFileBase? I have nearly 10 different class which accepts HttpPostedFileBase

I have a class as follows in c#

public class ArtGallery{
   Public string GallerName {get;set;}
   Public HttpPostedFileBase[] Documents {get;set;}
}

The equivalent JavaScript Model is

class ArtGallery{
     GallerName;
     Documents[];
}

On my save of the form here is how I am doing it

function saveFormData(){
  let gallery = new ArtGallery();
  gallery.GallerName = "Test";
  $.each($("input[type=file]"), function (i, obj) {
        $.each(obj.files, function (j, file) {
            gallery.Documents.push(file);
        });
   });
   saveToDb();
}

function saveToDb() {
    let url = "/MyController/PostData/";
    $.ajax({
        url: url,
        type: 'POST',
        async: false,
        data: '{gallery : ' + JSON.stringify(gallery) + '}',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (result) {
        },
        error: function (request) {
        }
    });
}

My controller is as follows, which is getting triggered but documents I am unable to get

[HttpPost]
public JsonResult PostUserData(ArtGallery gallery) {

}
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