How to pass IEnumerable model to controller

2019-08-04 09:31发布

My model is

public class InvBrojeviModel
{
    public int rb { get; set; }
    public int id_ulaz_sredstava { get; set; }

    public int? inv_broj { get; set; }

    public string serijski_broj { get; set; }

    public int id_sifra { get; set; }
}

I'm trying to pass this model to controller with an ajax call

    var m = '@Html.Raw(Json.Encode(Model))';

    $.ajax({
        url: "/Ulazna_Dokumenta/InvBrojevi_Post",
        type: 'POST',
        data: JSON.stringify(m),
        dataType: 'json',
        success: function (data) {
            alert("OK");
        }
    });

I can see the model is serialized. Serialized structure is

    "[{\"rb\":6477,\"id_ulaz_sredstava\":308,\"inv_broj\":6477,\"serijski_broj\":null,\"id_sifra\":29},{\"rb\":6478,\"id_ulaz_sredstava\":308,\"inv_broj\":6478,\"serijski_broj\":null,\"id_sifra\":29},{\"rb\":6479,\"id_ulaz_sredstava\":308,\"inv_broj\":6479,\"serijski_broj\":null,\"id_sifra\":29},{\"rb\":6480,\"id_ulaz_sredstava\":308,\"inv_broj\":6480,\"serijski_broj\":null,\"id_sifra\":29}]":

But in controller the input parameter is NULL. The controller is

     [HttpPost]
    public ActionResult InvBrojevi_Post(IEnumerable<Magacin.Models.InvBrojeviModel> _invBrojeviModel)
    {
        return Json("test");
    }

The input parameter _invBrojeviModel is NULL. Why?

0条回答
登录 后发表回答