I constructed a data model and passed the object into a cshtml view and it got properly displayed. 4 array items was constructed during constructor of the class, another 1000 array items in the Controller. All the items were properly displayed but when I submitted (FormMethod.Post), only the 4 array items got posted to the Controller.
My Controller Code:
Code:
public class HomeController : Controller
{
public IActionResult Index()
{
Submit s = new Submit();
for(int i=0; i < 1000; i++)
{
Model m = new Model(i,i.ToString());
s.list.Add(m);
}
return View(s);
}
public IActionResult KasiPost(Submit s)
{
return Ok();
}
My Data Model:
Code:
public class Submit
{
public List<Model> list{get;set;}=new List<Model>()
{
new Model(1,"One"),
new Model(2,"Two"),
new Model(3,"Three"),
new Model(4,"Four")
};
}
public class Model
{
public int ID{get;set;}
public string Name{get;set;}
public Model(int i, string n)
{
ID=i;
Name=n;
}
}
My View cshtml:
Code:
@model Submit
@using (Html.BeginForm("KasiPost","Home", FormMethod.Post))
{
<ul>
@for(int i=0; i<@Model.list.Count; i++)
{
@* <input type="hidden" asp-for="@Model.list[i].ID"/>
<input type="hidden" asp-for="@Model.list[i].Name"/> *@
<li>@Model.list[i].ID, @Model.list[i].Name</li>
}
</ul>
<input type="submit" value="Tekan"/>
}