MVC - Dropdownlist只返回第一个值,为什么?

时间:2016-07-06 06:50:53

标签: c# asp.net asp.net-mvc entity-framework linq

我在控制器中创建了一个List:

ReferenceError: bot2 is not defined
    at repl:1:1
    at REPLServer.defaultEval (repl.js:132:27)
    at bound (domain.js:291:14)
    at REPLServer.runBound [as eval] (domain.js:304:12)
    at REPLServer.<anonymous> (repl.js:279:12)
    at REPLServer.emit (events.js:107:17)
    at REPLServer.Interface._onLine (readline.js:214:10)
    at REPLServer.Interface._line (readline.js:553:8)
    at REPLServer.Interface._ttyWrite (readline.js:830:14)
    at ReadStream.onkeypress (readline.js:109:10)

我的观点:

var items = db.Message
              .Where(m => m.IDClient == id)
              .Select(c => new SelectListItem
                     {
                         Value = c.IDTexte.ToString(),
                         Text = c.Sujet,    
                     });
ViewBag.ListSujet = items;

但是当我选择一个值时,例如第三个值,它只返回第一个值,但我不知道为什么。

2 个答案:

答案 0 :(得分:1)

您可以编辑以下代码:

 ViewBag.ListSujet = new SelectList(db.Message.Where(m => m.IDClient == id), "IDTexte", "Sujet");

答案 1 :(得分:0)

您应该在模型中传递ItemId并将其绑定在查看器的下拉列表中。

library( data.table )
mydata <- fread( "household_power_consumption.txt" )

我希望它会对你有所帮助。