我的 asp.net mvc 应用程序中有以下操作方法:-
public ActionResult CustomersDetails(long[] SelectRight)
{
if (SelectRight == null)
{
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
RedirectToAction("Index");
}
else
{
var selectedCustomers = new SelectedCustomers
{
Info = SelectRight.Select(GetAccount)
};
return View(selectedCustomers);
}
return View();
}
但是如果它SelectRight Array
是空的,那么它将绕过if (SelectRight == null)
检查,它将呈现 CustomerDetails 视图并在视图内的以下代码上引发异常
@foreach (var item in Model.Info) {
<tr>
那么我怎样才能使空检查正常工作呢?