Ajax sending template to controller

Asked

Viewed 580 times

0

I wonder if it is possible to pass a "Model" object via ajax to my controller.

        $.ajax({
            type: "POST",
            url: "@Url.Action("CadastrarSementesVariedades", "SementesLevantamentoVariedades")",
            data: model,
        dataType: "html"
    });

I did it that way but it didn’t work, I’d have another way ?

  • Hello Samuel, could you post the rest of your code? Only with this it is not possible to locate the cause of the error.

1 answer

1


var obj = {id: $("#id").val(), descricao: $("#descricao").val()}

$.ajax({
        type: "POST",
        url: "@Url.Action("CadastrarSementesVariedades", "SementesLevantamentoVariedades")",
        data: obj});

public Class Objeto{
   public string id {get; set;}
   public string descricao {get; set;}
}

[httpPost]
public ActionResult CadastrarSementesVariedades(Objeto obj){
   //...
}

Depending on how you created your form, you can also serialize and send direct: date: $("#frm"). serialize()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.