开发者

List of Objects to be used on ascx view with Inherits data already loaded MVC

开发者 https://www.devze.com 2022-12-24 07:45 出处:网络
I have an object list being loded from a database to a drop down list.The Model loads the data to the Controller.The aspx view includes an ascx view.The ascx view already inherits data from another Pr

I have an object list being loded from a database to a drop down list. The Model loads the data to the Controller. The aspx view includes an ascx view. The ascx view already inherits data from another Project. I cannot set my List object in the ascx page. Can this be done?

Model

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

Controller

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

Partial View

        ...
        <select id="SelectedProperty">
           <% List<string> selectProperty = new List<string>();
           selectProperty = TempData["Select"] as Li开发者_如何转开发st<string>;
           foreach(var item in selectProperty) { %>
                <option><%=item.ToString() %></option>
           <% } %>
         </select>
         ...

Partial view's List should be an actual LossCauses object. HELP!!!


Change the partial view to

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号