这是视图代码,我使用的是TimeSheetView模型(以下提到)。我想存储一个带有日期和小时数的任务。如果可以的话请帮助我,我将非常感谢您。我应该改变我的模型吗?
@model Authentication.Models.TimeSheetViewModel
@{
ViewBag.Title = "Time Sheet";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Time Sheet</h2>
@using (Html.BeginForm("Create", "TimeSheet", FormMethod.Get))
{
var date_0 = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + (int)DayOfWeek.Monday);
<style>
.column {
float: left;
width: 10.79193%;
margin: 10px;
}
.row::after {
content: "";
display: table;
clear: both;
}
input {
width: 90%;
}
</style>
在这里我创建日期和任务的标题
<div class="row">
<div class="column">
<h4>Task</h4>
</div>
@for (int dates = 0; dates < 7; dates++)
{
<div class="column">
<h4>@date_0.AddDays(dates).ToString("dd/MM/yyyy")</h4>
<h4>@date_0.AddDays(dates).DayOfWeek</h4>
</div>
}
</div>
在这里,我正在创建文本框并将其数据存储在模型中。
for (int i = 0; i < 6; i++)
{
<div class="row">
@for (int j = 0; j < 8; j++)
{
if (j == 0)
{
<div class="column">
@Html.TextBoxFor(m => m.TaskDetails[j].Task)
</div>
}
else
{
<div class="column">
@Html.TextBoxFor(m => m.TaskDetails[j].Hours)
</div>
}
}
</div>
}
<input type="submit" />
}
这是模特
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Authentication.Models
{
public class TimeSheetViewModel
{
public List<TaskList> TaskDetails { get; set; }
}
public class TaskList
{
public string Task { get; set; }
public decimal Hours { get; set; }
public DateTime TaskDate { get; set; }
}
}
我应该更改我的模型吗?