【问题标题】:EditorForModel and DisplayForModel do not work then passing class model within class modelEditorForModel 和 DisplayForModel 不起作用,然后在类模型中传递类模型
【发布时间】:2012-12-04 14:55:29
【问题描述】:

也许有人可以解释为什么 EditorForModel 和 DisplayForModel 不在网页上显示任何数据?

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

【问题讨论】:

    标签: asp.net asp.net-mvc-3


    【解决方案1】:

    默认情况下EditorForModelDisplayForModel 不显示或递归复杂属性。您可以通过实现 Object.cshtml 模板来启用此功能。

    【讨论】:

      猜你喜欢
      • 2013-08-07
      • 2021-06-07
      • 2019-04-24
      • 1970-01-01
      • 2021-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      相关资源
      最近更新 更多