我的控制器中有这个方法,称为“DirectorySearchController”
public ActionResult PersonDetails(FoundPerson person) //for some reason person is null here
{
DirectoryViewModel viewModel = new DirectoryViewModel();
viewModel.person = person;
return View(viewModel);
}
当我使用 Html.Actionlink 从视图向它传递一些参数时,它返回一个空值
<ul data-role="listview">
@if (ViewBag.Message == "NO RESULTS FOUND")
{
<li>@ViewBag.Message</li>
}
else
{
foreach (var employee in Model)
{
<li>
<div class="ui-grid-b">
<div class="ui-block-a" style="width:20%; vertical-align:middle"><img src="@employee.pictureURL" width="40px" height="40px"/></div>
<div class="ui-block-b" style="width:80%; vertical-align:middle">@Html.ActionLink(employee.name, "PersonDetails", "DirectorySearch", new { person = employee}, null)</div>
</div>
</li>
}
}
</ul>
但有趣的是,当我在不使用“new”关键字的情况下传递参数时,它传递了正确的值。但是,问题是我需要传递多个参数,所以我需要使用“new”关键字。
<div class="ui-block-b" style="width:80%; vertical-align:middle">@Html.ActionLink(employee.name, "PersonDetails", "DirectorySearch", employee, null)</div>