---
title: "I am using mvc4 in that i am using grid view in that it is not searching a data"  
description: "I am using mvc4 in that i am using grid view in that it is not searching a data"  
author: "anand kumar"  
published: 2016-08-05  
updated: 2016-08-05  
canonical: https://www.mindstick.com/forum/34159/i-am-using-mvc4-in-that-i-am-using-grid-view-in-that-it-is-not-searching-a-data  
category: "asp.net mvc"  
tags: ["mvc4"]  
reading_time: 5 minutes  

---

# I am using mvc4 in that i am using grid view in that it is not searching a data

this is my [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc)\

```
 [HttpPost]        public ActionResult SearchResult(string SearchKey)        {            ProductDetailModel obj = new ProductDetailModel();            obj.ProductList = ProductId(SearchKey);            string strTable = "";            strTable = strTable + "< table>< thead>< tr>< th>Id</ th >< th >Product_Name</ th >";            strTable = strTable + "< th >Product_Detail</ th >< th >price< / th></ tr></ thead>< tbody>";            foreach (var item in obj.ProductList)            {                strTable = strTable + "< tr >";                strTable = strTable + "< td >" + item.Id + "</ td >";                strTable = strTable + "< td >" + item.Product_Name + "</ td >";                strTable = strTable + "< td >" + item.Product_Detail + "</ td >";                strTable = strTable + "< td>" + item.price + "</ td >";                strTable = strTable + "</ tr >";            }            strTable = strTable + "</ tbody ></ table >";            return View(strTable);        }                [HttpGet]        public List<product> ProductId(string SearchKey)        {            List<product> objProduct = new List<product>();            gridEntities objDemoEntities = new gridEntities();            var productItem = from data in objDemoEntities.grids                              where SearchKey == "" ? true : data.Product_Name.Contains(SearchKey)                              select data;                        foreach (var item in productItem)                {                    objProduct.Add(new product                    {                        Id =(int) item.Id,                        Product_Name = item.Product_Name,                        Product_Detail = item.Product_Details,                        price = (int)item.price                    });                }                return objProduct;            }
```

\
**this is my [Index](https://www.mindstick.com/blog/198/index-in-sql-server).[view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view)**

```
@model grid01.Models.ProductDetailModel@{    ViewBag.Title = "SearchResult";}<script src="../../js/jquery-1.4.1.min.js" type="text/javascript"></script><script language="javascript">    function AjaxSearch() {        var searchUrl = "Home/SearchResult/?SearchKey=" + $("#SearchKey").attr('value');        $("#btnSearch").attr({ 'value': 'Please wait..' });        $.ajax({            url: "SearchUrl",            type: "POST",            success: function (data) {                $("#divData").html(data);                $("#btnSearch").attr({ 'value': 'Search' });            }        });    }</script>@using (@Html.BeginForm("Index", "Home")){    <table border="0">        <tr>            <td align="right">                Search: @Html.TextBox("SearchKey", "", new { })            </td>            <td align="left">                <input type="button" value="Search" onclick="javascript:AjaxSearch();" id="btnSearch" />            </td>            <td>                <p>                    @Html.ActionLink("Insert", "add")                </p>            </td>        </tr>    </table>             <div id="msgwait"></div>    <div id="divData">        <div style="text-align:center;display:@Model.ProductList">            @{    var grid = new WebGrid(Model.ProductList, canSort: false);    @grid.GetHtml(    tableStyle: "Grid-table",     headerStyle: "Grid-Header",     alternatingRowStyle: "Grid-alt",     selectedRowStyle: "Grid-selected",     rowStyle: "Grid-rowstyle",     footerStyle: "Grid-Footer",    columns:                grid.Columns                (                        grid.Column("Id", "Id"),                        grid.Column("Product_Name", "Product_Name"),                        grid.Column("Product_Detail", "Product_Detail"),                        grid.Column("price", "price")        ), mode: WebGridPagerModes.All);            }                    </div>        </div>    foreach (var item in Model.ProductList)    {                                <tr>                                    <td>                                        @Html.ActionLink("Edit", "Edit", new { id = item.Id })                                    </td>                                </tr>                                }                                   }
```

\
\


---

Original Source: https://www.mindstick.com/forum/34159/i-am-using-mvc4-in-that-i-am-using-grid-view-in-that-it-is-not-searching-a-data

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
