Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to, pass the list of objects, from view to the controller's action. I gave "List<api_vm> model, IList<api_vm> model, API_VM[] model" as parameters on action and I gave "IList<api_vm>, List<api_vm>" as model on View page. but it doesn't work. Model is null all time.

C#
[HttpGet]
    public IActionResult UrunlerListe(API_VM model)
    {
        XElement stok = XElement.Load(model.TedarikciLink);
       List<API_VM> ApiList = new List<API_VM>();
        model.Stoklar = stok.Descendants(model.ParentElement).ToList();
        ViewBag.Tedarikci = model.TedarikciLink;
        foreach (var item in model.Stoklar)
        {
            API_VM api = new API_VM();
            api.UrunAdi = item.Element(model.UrunAdi).Value;
            api.Kategori = item.Element(model.Kategori).Value;
            api.UrunAciklama = item.Element(model.UrunAciklama).Value;
            api.UrunFiyat = item.Element(model.UrunFiyat).Value;
            api.UrunMarka = item.Element(model.UrunMarka).Value;
            api.PaketAgirligi = item.Element(model.PaketAgirligi).Value;
            api.PaketGenisligi = item.Element(model.PaketGenisligi).Value;
            api.PaketUzunlgu = item.Element(model.PaketUzunlgu).Value;
            api.PaketYuksekligi = item.Element(model.PaketYuksekligi).Value;
            api.StokAded = item.Element(model.StokAded).Value;
            api.UrunFoto1 = item.Element(model.UrunFoto1).Value;
            api.UrunFoto2 = item.Element(model.UrunFoto2).Value;
            api.UrunFoto3 = item.Element(model.UrunFoto3).Value;
            api.UrunFoto4 = item.Element(model.UrunFoto4).Value;
            api.UrunFoto5 = item.Element(model.UrunFoto5).Value;
            api.UrunFoto6 = item.Element(model.UrunFoto6).Value;
            
            ApiList.Add(api);
        }
        
        return View(ApiList);
    }

HTML
@model IList<API_VM>
@{
    ViewData["Title"] = "UrunlerListe";
    Layout = "~/Views/Shared/_Layout.cshtml";


}
<form asp-action="UrunlerListe" method="post">

    @for (int i = 0; i <Model.Count(); i++)
    {
        @Html.TextBoxFor(model => Model[i].UrunAdi)
    }
    <input type="submit" value="ürünleri gönder" />
</form>

C#
[HttpPost]
   public IActionResult UrunlerListe(API_VM[] model)
   {
       //work
   }


What I have tried:

C#
[HttpPost]
   public IActionResult UrunlerListe(API_VM[] model)
   {
       //work
   }

C#
[HttpPost]
   public IActionResult UrunlerListe(List<API_VM> model)
   {
       //work
   }

C#
[HttpPost]
   public IActionResult UrunlerListe(IList<API_VM> model)
   {
       //work
   }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900