【发布时间】:2012-12-24 06:06:44
【问题描述】:
我的 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>
那么我怎样才能使空检查正常工作呢?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-3