我希望通过从SharePoint列表中检索来显示表中的一些记录。我将它用作@HtmlBeginForm用于提交目的。 在我的情况下,有三个按钮,
上一页 - 预览以前的日期记录
next - 预览下一个日期记录
提交 - 更新共享点列表(更改表值后)
页面加载时从今天到最后7天将数据加载到表格。
在我的情况下,虽然记录检索正确,但表格不会显示更新的值。它显示默认加载的值。
我的表 - :
@using (Html.BeginForm())
{
<table border="1" class="table timetrack-tb">
<tr>
<th>Projects</th>
@for (var date = @Model.Dates.AddDays(-(@Model.DateRange - 1)); date <= @Model.Dates; date = date.AddDays(1))
{
<th>@date.Day/@date.Month/@date.Year</th>
}
<th>Total</th>
</tr>
@{ double[] totalForDay = new double[@Model.DateRange+1];
double[] total = new double[@Model.TimeTrakings.Count];}
@for (int i = 0; i < @Model.TimeTrakings.Count; i++)
{
var projectName = @Model.TimeTrakings[i][0].ProjectName;
int index = 0;
<tr>
<td>
@Model.TimeTrakings[i][0].ProjectName
</td>
@for (int j = 0; j <= Model.TimeTrakings[i].Count(); j++)
{
if (j != Model.TimeTrakings[i].Count())
{
totalForDay[index] = totalForDay[index] + @Model.TimeTrakings[i][j].Hours;
total[i] = total[i] + @Model.TimeTrakings[i][j].Hours;
<td>
@Html.EditorFor(model => @Model.TimeTrakings[i][j].Hours)
@Html.HiddenFor(x => x.TimeTrakings[i][j].Id)
@Html.HiddenFor(x => x.DateRange)
@Html.HiddenFor(x => x.TimeTrakings[i][j].ProjectName)
@Html.HiddenFor(x => x.TimeTrakings[i][j].ProjectCode)
@Html.HiddenFor(x => x.TimeTrakings[i][j].Date)
</td>
index++;
}
else
{
totalForDay[index] = totalForDay[index] + total[i];
index++;
}
}
<td>@total[i]</td>
</tr>
}
<tr>
<td>Total for day</td>
@foreach (var tot in totalForDay)
{
<td>@tot</td>
}
</tr>
</table>
<input type="submit" name="prevBtn" value="Prev" />
<input type="submit" name="NextBtn" value="Next" />
<input type="submit" name="SubmitBtn" value="Submit"/>
}
我的控制器方法:
public ActionResult Index(TimeTracking timeTracking)
{
DateTime today = DateTime.Today;
int lengthOfTable = timeTracking.DateRange;
if (Request.Form["SubmitBtn"] != null)
{
timeTrackManager.UpdateTimeTrackingList(timeTracking);
today = DateTime.Today;
lengthOfTable = timeTracking.DateRange;
}
else if (Request.Form["prevBtn"] != null)
{
today = timeTracking.TimeTrakings[0][0].Date.AddDays(-1);
lengthOfTable = timeTracking.DateRange;
}
else if (Request.Form["NextBtn"] != null)
{
today = timeTracking.TimeTrakings[0][0].Date.AddDays(timeTracking.DateRange);
lengthOfTable = timeTracking.DateRange;
}
return View(this.ReceiveTimeTrackingData(today, lengthOfTable));
}