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

114
Vistas
Unable to send view data from ajax jquery to model or controller method as parameter in dot net core mvc
$("#btnSubmit").click(function() {
  debugger
  var Pid = $("#hdnPid").val();
  console.log(formdata);

  $("loader-area,.loader").css("display", "block");

  $.ajax({
    url: '@Url.Action("InsertUpdateProduct")',
    contentType: 'application/json; charset=utf-8',
    data: $('#formId').serialize(),
    type: 'POST',
    success: function(data) {
        debugger
        if (data[0].Retval = "1") {
          toastr.success('Record Saved Successfully.', 'Congratulations!');
        } else if (data[0].Retval = "2") {
          toastr.success('Record Updated Successfully.', 'Congratulations!');
        } else {
          toastr.warning('Exception Occured', 'Warning!');
        }
        ProductMaster();
        ClearData();
      }

      - List item
  });
});

Controller

[HttpPost]
public JsonResult InsertUpdateProduct(ProductMaster productMaster, IFormFile files) 
{
  List<ProductMaster> ObjProduct = new List<ProductMaster>();
  try 
  {
    if (ModelState.IsValid)   
    {
      if (files != null) 
      {
        if (files.Length > 0) 
        {
          //Getting FileName
          var fileName = Path.GetFileName(files.FileName);

          //Getting file Extension
          var fileExtension = Path.GetExtension(fileName);

          // concatenating  FileName + FileExtension
          var newFileName = String.Concat(Convert.ToString(Guid.NewGuid()), fileExtension);

          var objfiles = new ProductMaster() 
          {
            //DocumentId = 0,
            ImageName = newFileName,
            FileType = fileExtension,
            // CreatedOn = DateTime.Now
          };

          using(var target = new MemoryStream()) 
          {
            files.CopyTo(target);
            objfiles.Image = target.ToArray();
            productMaster.Image = objfiles.Image;
          }
        }
      }

      //productMaster.PID = PID;            
      objProductData.InsertUpdateProduct(productMaster);
      if (productMaster.PID == 0) 
      {
        _notyf.Success("Record Saved Successfully");
      } 
      else 
      {
        _notyf.Success("Record Updated Successfully");
      }
    } 
    else 
    {
      _notyf.Warning("Model false display");
    }
  } 
  catch (Exception ex) 
  {
    _notyf.Error("Error Occured");
  }
  return Json(ObjProduct);
}
about 4 years ago · Juan Pablo Isaza
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