I have a class
public class Citizen
{
public long ID { get; set; }
public string Name { get; set; }
public long CityID { get; set; }
public stri
The expression you sent causes that name:
What I get is name="Resources[0].CurrentAmount" which then doesn't map correctly to the CitizenResource class.
@Html.EditorFor(model => model.Resources[i].CurrentAmount, new { htmlAttributes = new { @class = "form-control" } })
Instead have a partial view to edit an CitizenResource
@model CitizenResource
@using(Html.BeginForm("EditResource", "Citizen")){
{
//The complete elements
@Html.EditorFor(model => model.CurrentAmount, new { htmlAttributes = new { @class = "form-control" } })
//The rest of the elements
}}
Your code is creating multiple forms which is not good. The best way to handle this kind of scenario is the use of EditorTemplates. Checkout this link on how to do it. EditorFor() for a List of Complex Type (MVC)