Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i select nothing and click button then i get all record but if i select any name from dropdonw i didnt get anything...!!

if i tack textbox then it's working properly

What I have tried:

i use mvc 3-tier

C#
//ball
 public List<mone> searchajax(string search)
      {
       
          List<mone> lst = new List<mone>();

          lst = (from p in db.onetbls
                 where p.name.Contains(search)
              
                 select new mone
                     {
                         id = p.id,
                         name = p.name,
                         city = p.city,
                         state = p.state,
                         comments = p.cournt,
                         cournt = p.cournt,
                         
                     }).ToList<mone>();
          return lst;
      }


C#
//controller


  public ActionResult search(string search)
        {
            ViewBag.search = new SelectList(db.onetbls, "id", "name");
            List<mone> lst = new List<mone>();
            lst = lc.searchajax(search);
            return View(lst);
        }



HTML
//view


@model IEnumerable<bal.models.mone>

@{
    ViewBag.Title = "search";
}

<h2>search</h2>
@using(Html.BeginForm())
{
    @*@Html.TextBox("search")*@
    @Html.DropDownList("search", "select")
<input type="submit" />
    

}

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.city)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.state)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.cournt)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.img)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.email)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.gender)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.oid)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.comments)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.fid)
        </th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.city)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.state)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.cournt)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.img)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.email)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.gender)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.oid)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.comments)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.fid)
        </td>
       
    </tr>
}
Posted
Updated 23-May-16 7:38am
v2
Comments
Karthik_Mahalingam 21-May-16 6:59am    
Place breakpoint and check what you getting in the search string and the collection..
Jaydeep Shah 21-May-16 7:19am    
suppose i select any one name it get value(i.e= 39) at controller and ball both but at
lst = (from p in db.onetbls....) (in bll) it give count = 0

i know it's return nothing but what can i do now ..!
Karthik_Mahalingam 21-May-16 7:23am    
does this [db.onetbls] has values for the keyword which you are searching...
Jaydeep Shah 21-May-16 7:42am    
db is entity name. and onetbls is my table name...

ya..mytable contain..name,city,coutnry,state ok and in dropdonw i put name search so dafinatlly it contain atleast one value
Karthik_Mahalingam 21-May-16 7:30am    
how many items are there in db.onetbls ?

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