【发布时间】:2014-04-16 07:10:26
【问题描述】:
我有一个 IList 对象,我使用 ViewModel 将其传递给我的视图。
[HttpGet]
public ActionResult Reminder()
{
using(var db = new SalonContext())
{
var tomorrow = DateTime.Today.AddDays(1);
var homeSalon = GetHomeSalonId();
var myAppointments = db.Appointments.Include(c => c.Customer).Include(c => c.Treatment).Include(c => c.Stylist).Include(c => c.Salon).Where(c => c.SalonId == homeSalon).ToList();
var tomorrowsAppointments = myAppointments.Where(a => a.Start.Date == tomorrow).Select(rem => new FutureAppointment
{
AppointmentId = rem.AppointmentId,
Name = rem.Customer.Title + " " +rem.Customer.FirstName + " " + rem.Customer.Surname,
AppointmentTime = rem.Start,
Salon = rem.Salon.Name,
Stylist = rem.Stylist.FirstName,
Treatment = rem.Treatment.Name,
Email = rem.Customer.EMail,
SendReminder = true
}).ToList();
return View(tomorrowsAppointments);
}
}
视图使用以下代码呈现带有复选框的列表:
@model IList<MySalonOrganiser.Models.FutureAppointment>
@{
ViewBag.Title = "Email Reminders";
}
<h2>@ViewBag.Title</h2>
@using(Html.BeginForm("Reminder", "Appointment", FormMethod.Post))
{
@Html.AntiForgeryToken()
<table class="table">
<tr>
<th>
Send Reminder
</th>
<th>
Name
</th>
<th>
Appointment Time
</th>
<th>
Salon
</th>
<th>
Treatment
</th>
<th>
Stylist
</th>
<th>
EMail
</th>
<th></th>
</tr>
@for (var i =0; i < Model.Count; i++)
{
<tr>
<td>
@Html.CheckBoxFor(x => x[i].SendReminder)
</td>
<td>
@Html.DisplayFor(x => x[i].Name)
</td>
<td>
@Html.DisplayFor(x => x[i].AppointmentTime)
</td>
<td>
@Html.DisplayFor(x => x[i].Salon)
</td>
<td>
@Html.DisplayFor(x => x[i].Treatment)
</td>
<td>
@Html.DisplayFor(x => x[i].Stylist)
</td>
<td>
@Html.DisplayFor(x => x[i].Email)
</td>
</tr>
}
</table>
<div>
<input type="Submit" value="Send Reminders" />
</div>
}
当我将视图发布回控制器时,我在返回的模型中看到了 FutureAppointment 类型的列表项,但是除了复选框状态之外的所有内容都是空的。
谁能帮助我解决这个问题的原因和方法,以便我查看所有模型数据?
杰森。
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-5