我试图编写允许我执行以下操作的代码:
How I envision the screen looking like (X's are checked boxes)
现在我对如何完成大部分工作有相当多的了解。但是我真的迷失了我可以绘制表格的部分。我希望能指出正确的方向。
简单控制器:
public TaskplannerController : Controller
{
[HttpGet]
public ActionResult Index()
{
var model = new TaskplannerViewModel();
return View(model);
}
[HttpPost]
public ActionResult Index(TaskplannerViewModel model)
{
model.ProjectDurationInMonths = model.GetProjectDuration();
return View(model);
}
}
使用ViewModel:
public class TaskplannerViewModel
{
public IEnumerable<SelectListItem> Types;
public IEnumerable<SelectListItem> Projects;
public IEnumerable<DateTime> ProjectDurationInMonths;
public int Id { get; set; }
public int ProjectId { get; set; }
public string TaskDescription { get; set; }
public int TypeId { get; set; }
public int MaxTimeInMinutes { get; set; }
public EditPoTaakViewModel()
{
PopulateSelectLists();
}
private void PopulateSelectLists()
{
var taskType = new TaskType();
TaskTypes = type.GetAll();
var project = new Project();
Projects = project.GetAll();
}
public IEnumerable<DateTime> GetProjectDuration()
{
var project = new Project();
var selectedProject = project.Get(ProjectId);
DateTime startDate = selectedProject.StartDate;
DateTime endDate= selectedProject.endDate;
while(startDate <= endDate)
{
yield return startDate;
startDate = startDate.AddMonths(1);
}
}
}
答案 0 :(得分:0)
我认为asp中继器可能是您需要的。
看起来像这样:
<asp:Repeater runat="server">
<HeaderTemplate>
<table>
<tr class="Headertemplate">
<th style="display:none;">ID</th>
<th>Task</th>
<th>Type</th>
<th>Max time in minutes</th>
<th>Month</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="Itemtemplate">
<td><asp:Label Text="text" runat="server" /></td>
<td>
<asp:DropDownList runat="server">
<asp:ListItem Text="text1" />
<asp:ListItem Text="text2" />
</asp:DropDownList>
</td>
<td><asp:TextBox runat="server" /></td>
<td><asp:CheckBox Text="text" runat="server" /></td>
<td></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>