Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
public ActionResult Search(string pName, string pBankCode)
       {
           Bank bank = db.Banks.Where(o => o.DealerCode == pName && o.BankCode == pBankCode).FirstOrDefault();
           if (bank == null)
           {
               return HttpNotFound("Nothing Here to Displays");
           }
           return View(bank);
       }


View Code like this

C#
@model  MyMvcWeb.Models.Bank

@{
    ViewBag.Title = "Search";

}



@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.DealerCode)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.BankCode)
        </td>


but there is loop give error

can we use foreach loop in view for model
Posted

here, no need to use for-each loop because you are not returning a list from Model...
simply use this
HTML
<td>
    @Html.DisplayFor(model => model.DealerCode)
</td>
<td>
    @Html.DisplayFor(model => model.BankCode)
</td>

and remove
HTML
@foreach (var item in Model){
 
Share this answer
 
v2
Comments
saimm 12-Jan-15 3:18am    
then how i can display in table of razor model values
saimm 12-Jan-15 3:18am    
i want to make search in model of mvc and display in table
saimm 12-Jan-15 3:23am    
ok thanx ,, i got it ur points ,, thnx
Er. Ajay Chauhan 12-Jan-15 3:23am    
what do you want to do on this page....?? displaying a list or simply a record...??
not everyone understands what you share, and it's not something I want. http://www.yepi2gamer.com
 
Share this answer
 
Comments
saimm 12-Jan-15 3:18am    
i want to make search in model of mvc and display in table

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900