EditorForModel and DisplayForModel do not work the

2019-09-19 03:10发布

问题:

Maybe someone could explain why EditorForModel and DisplayForModel do not display any data on web page?

  public class QueueManagerModel
    {
        public RemoveModel Remove { get; set; }
        public StatisticModel Statistic { get; set; }


        public class RemoveModel
        {
            public bool Deleted { get; set; }
            public bool ValidationFailled { get; set; }
            public bool Validated { get; set; }
            public bool Uploading { get; set; }
        }

        public class StatisticModel
        {
            public int Deleted { get; set; }
            public int ValidationFailled { get; set; }
            public int Validated { get; set; }
            public int Uploading { get; set; }
        }

    }

  public ActionResult QueueManager()
        {
            var queueManagerModel = new QueueManagerModel();
            queueManagerModel.Remove = new QueueManagerModel.RemoveModel();
            queueManagerModel.Statistic = new QueueManagerModel.StatisticModel();
            return View(queueManagerModel);
        }

@model PC.Models.QueueManagerModel
@using (Html.BeginForm())
{
    <fieldset>
        <legend>Queue Manager</legend>
        @Html.EditorForModel(Model.Remove)
        @Html.DisplayForModel(Model.Statistic)
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

回答1:

By default EditorForModel and DisplayForModel does not display or recurse complex properties. You can enable this by implementing an Object.cshtml template.