我构建了一个有4层的解决方案
1-One解决方案(数据访问层)具有来自不同数据库的多个(DAL)。
2-Data Store(访问所有DAL)。
3-Business Layer BL(haslogicalmethods)
4-Presentation layer(MVC4)。
问题是我想在DAL(建立)中通过BLL用Para Name调用列表搜索方法来搜索它,并希望在PL中的View中显示结果。 EstController
public ActionResult Index(string Name)
{
if (Name != null)
{
IList list = BLL.Establishment_Serv.getEstablishmentByName(Name.ToUpper());
return View(list);
}
return View();
}
和Est / Index View
@using (Html.BeginForm("Index" ,"Est",FormMethod.Get))
{
<p>
Find by name: @Html.TextBox("Name")
<input type="submit" value="Search" />
</p>
}
<table>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.Id)</td>
<td>@Html.DisplayFor(modleItem => item.Name)</td>
</tr>
}
</table>
我在foreach声明中遇到错误。如果有最佳方法,请告诉我。
答案 0 :(得分:3)
你有没有把它放在你的观点中:
@model IEnumerable<YourModel>
答案 1 :(得分:0)
如果您的列表为null,那么您将收到错误
public ActionResult Index(string Name)
{
var list=new List<YourModelName>();
if (Name != null)
{
list = BLL.Establishment_Serv.getEstablishmentByName(Name.ToUpper());
return View(list);
}
else {
return View(list);
}
}