我在最近3个小时里一直在敲我的头,我不知道出了什么问题。
我的问题是,当我在ProjectCode
中提交空白值时,为什么HTML帮助程序无效。以下是我的视图和控制器?
查看:
@using Models;
@model LoginViewModel
@{
ViewBag.Title = "Login";
Layout = "~/Views/_MainTheme.cshtml";
}
@using (Html.BeginForm("Search", "Home", FormMethod.Get))
{
@Html.TextBoxFor(x => x.ProjectCode)
<input type="submit" name="Search" value="Search" />
<br />
@Html.ActionLink("Create", "Details", "NewSurvey")
<br />
<div style="display:@(Model.SurveyList.Surveys.Count > 0 ? "block" : "none");">
<div>@Model.SurveyListTableHeader</div>
<table border="1">
<thead>
<tr>
<td>Project Code</td>
<td>Project Name</td>
</thead>
@foreach (var survey in Model.SurveyList.Surveys)
{
<tr>
<td>@survey.Value.ProjectCode</td>
<td>@survey.Value.ProjectName</td>
}
</table>
</div>
}
控制器:
public ActionResult Login()
{
Session["CurrentPage"] = ePages.Login;
LoginViewModel login = new LoginViewModel();
login.SurveyList = BusinessOperations.GetExistingUserSurveys("mp12672", ref ScreenMessages._Message, ref ScreenMessages._MessageStateID);
login.SurveyListTableHeader = "Recently Accessed Surveys";
return View("Login", login);
}
public ActionResult Search(LoginViewModel login)
{
Session["CurrentPage"] = ePages.Login;
login.SurveyList = BusinessOperations.GetProjectSurveys(login.ProjectCode, ref ScreenMessages._Message, ref ScreenMessages._MessageStateID);
login.SurveyListTableHeader = "Surveys matching your search";
return View("Login", login);
}
public ActionResult Resume(string SurveyKey)
{
Session["SurveyKey"] = SurveyKey;
return RedirectToAction("Introduction", "OMS");
}
}
我得到的例外是:
异常详细信息:System.NullReferenceException:未将对象引用设置为对象的实例。
在下面一行
@Html.ActionLink("Create", "Details", "NewSurvey")