我正在尝试按日期进行搜索过滤,但出现错误。这是我的搜索方法:
public ActionResult Search(DateTime StartDate,DateTime EndDate)
{
var result = (
from r in context.Rooms
from v in context.Reservations
.Where(a =>a.Room_ID == r.RoomID
&&
!(
StartDate >= a.Data_Check_out ||
EndDate <= a.Data_Check_in
)
&& a.Cancel == false
).DefaultIfEmpty()
where v.ReservationID == null
select r
);
return View(result);
}
这是我的观点:
@model IEnumerable<MvcApplication4.Models.Room>
@using (Html.BeginForm("Search", "Room", FormMethod.Get))
{
@Html.TextBox("StartDate")
<input type="submit" value="Search" />
@Html.TextBox("EndDate")
<input type="submit" value="Search" /> }
@foreach (var x in Model)
{
<div class="item">
<h1>@x.Room_Type.Room_Type1</h1>
</div>}`
我收到以下错误:
参数字典包含“MvcApplication4.Controllers.RoomController”中方法“System.Web.Mvc.ActionResult Search(System.DateTime, System.DateTime)”的不可为空类型“System.DateTime”的参数“StartDate”的空条目'。可选参数必须是引用类型、可空类型或声明为可选参数。参数名称:参数`