【问题标题】:List of Objects to be used on ascx view with Inherits data already loaded MVC要在 ascx 视图上使用的对象列表,其中继承数据已加载 MVC
【发布时间】:2010-03-29 18:45:53
【问题描述】:

我有一个从数据库加载到下拉列表的对象列表。模型将数据加载到控制器。 aspx 视图包括一个 ascx 视图。 ascx 视图已经从另一个项目继承数据。我无法在 ascx 页面中设置我的 List 对象。这个可以吗?

型号

        ...
        string List = dr["example"].ToString().Trim();
        int indicator = dr["ex"].ToString().Trim();
        LossCauseList.Add(new LossCauses(indicator, List));
        ...

控制器

        LossCauses test = new LossCauses();
        test.GetLossCauses(LossType);
        TempData["Select"] = test.LossCauseList;
        return View(myData);

局部视图

        ...
        <select id="SelectedProperty">
           <% List<string> selectProperty = new List<string>();
           selectProperty = TempData["Select"] as List<string>;
           foreach(var item in selectProperty) { %>
                <option><%=item.ToString() %></option>
           <% } %>
         </select>
         ...

部分视图的列表应该是一个实际的 LossCauses 对象。救命!!!

【问题讨论】:

    标签: c# html asp.net-mvc asp.net ascx


    【解决方案1】:

    将局部视图改为

    List<LossCauses> selectProperty = TempData["Select"] as List<LossCauses>;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多