MVC5 Asp.net Is there a way to get the correct value from EditorFor for a subclass

后端 未结 2 1696
伪装坚强ぢ
伪装坚强ぢ 2021-01-28 12:56

I have a class

public class Citizen
{
    public long ID { get; set; }
    public string Name { get; set; }
    public long CityID { get; set; }
    public stri         


        
2条回答
  •  余生分开走
    2021-01-28 13:03

    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
    }}
    

提交回复
热议问题