Reputation: 47
I build a solution has 4 layers
1-One Solution (Data Access layer) has multi (DALs) from diffrent DBs.
2-Data Store(access all DALs).
3-Business Layer BL(haslogicalmethods)
4-Presentation layer (MVC4).
the problem is I want call a list search methods in DAL(Establishment) through BLL with Para Name to search it , and want to show the result in View in PL. the EstController
public ActionResult Index(string Name)
{
if (Name != null)
{
IList list = BLL.Establishment_Serv.getEstablishmentByName(Name.ToUpper());
return View(list);
}
return View();
}
and 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>
and I face an error in foreach statement.And if there a best approach to doing it HINT me please.
Upvotes: 2
Views: 10884
Reputation: 2648
if your list is null then you will get error
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);
}
}
Upvotes: 0