如何在模型值MVC4中使用列表

时间:2014-05-06 10:43:41

标签: asp.net-mvc linq asp.net-mvc-4

我有一个列表,我希望传递一个模型值。

var playid = (from u in playlist
              select new { u.listtitle, u.Id }).ToList();

在模型中使用它

 var list = new Addvideo
                            {
                                videoname = data.videoname,
                                Ch_Name = data.Ch_Name,
                                videopath = data.videopath,
                                Video_view = Convert.ToInt64(data.Video_View),
                                listname = playid

                            };

我想在模型实体listtitle中同时使用Idlistname

我之前尝试过这个 -

listname=playid.Select(m=>new{title=m.listtitle,id=m.Id}).ToList();

但这不起作用。

使用以下视图 -

@foreach (var item in Model.listname)
                        {
                            <li><a href="javascript:;">@item</a></li>

                            <li class="pull-right"><a href="#">Add to playlist</a></li>
                        }

1 个答案:

答案 0 :(得分:0)

public class Addvideo
{
  string videoname {get;set;}
  string Ch_Name {get;set;}
  string videopath {get;set;}
  long Video_view {get;set;}
  IList <Listname> listname {get;set;}
}


public class Listname
{
  string Title {get;set;}
  int Id {get;set;}
}

var playid = (from u in playlist
              select new Listname() { Title = u.listtitle, Id = u.Id }).ToList();

 var list = new Addvideo
                            {
                                videoname = data.videoname,
                                Ch_Name = data.Ch_Name,
                                videopath = data.videopath,
                                Video_view = Convert.ToInt64(data.Video_View),
                                listname = playid    
                            };