【发布时间】:2015-03-09 14:54:29
【问题描述】:
我正在做一个学校项目,但在我看来,我被困在一个下拉列表中。所以这是我的 ViewModel:
using System;
using System.Collections.Generic;
using System.Linq;
using Klimatogrammen.Models.Domain;
namespace Klimatogrammen.ViewModels
{
public class VraagViewModel
{
public String Question { get; private set; }
public String Code { get; private set; }
public List<double> Answers { get; private set; }
public VraagViewModel(Parameter temp, Klimatogram klim)
{
Question = temp.Naam;
Code = temp.Code;
Answers = temp.GeefMogelijkeAntwoorden(klim).ToList();
}
}
}
以及相关的View
@model IEnumerable<Klimatogrammen.ViewModels.VraagViewModel>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Question)
</th>
<th>
@Html.DisplayNameFor(model => model.Answers)
</th>
@Html.DropDownListFor(Model)
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Question)
</td>
<td>
@Html.DropDownListFor(new SelectList(item.Answers))
</td>
</tr>
}
</table>
所以我想要一个双打列表作为问题的答案。每个问题都有自己的具体答案,我想在每个问题旁边显示它们的可能性。
我尝试了一些方法,但找不到解决方案(从选择列表到选择项等,但我没有值或文本,我只想显示双打)。我的观点也必须保持IEnumerable(我有我的理由)
任何人都可以分享一些关于这方面的信息吗?
【问题讨论】:
-
你的视图需要是
List<T> -
什么意思?
IEnumerable<ViewModel>?
标签: c# asp.net asp.net-mvc view viewmodel