在 webgrid 剃刀上搜索

search on webgrid razor

我正在尝试在我的网络网格上搜索数据,但是当我从下拉菜单中进行选择或在文本框中键入时,数据消失了。

我已关注此 link:http://www.mikesdotnetting.com/article/180/displaying-search-results-in-a-webgrid

代码如下。请协助。

@{
    Layout = "~/_SiteLayout.cshtml";
    Page.Title = "Payment Schedule";
    var db = Database.Open("GroupCashFlow");
    var query = "SELECT DISTINCT Company FROM PaymentSchedule ORDER BY Company";
    var companies = db.Query(query);
    query = "SELECT *  FROM dbo.PaymentSchedule where Account like @0 and Company like @1"; 
    var account = "%" + Request["account"] + "%";
    var company = "%" + Request["company"] + "%";
    var data = db.Query(query, account,company);
    var columns = new[]{"Date","Company","Account", "Payee","Section","Category","Product","Currency","Amount","FX","USD","Comments"};
    var grid = new WebGrid(data,columnNames: columns,rowsPerPage: 20);
}

<!DOCTYPE html>

<html lang="en">

    <head>
        <meta charset="utf-8" />
        <style type="text/css">
          .grid { margin: 4px; border-collapse: collapse; width: 600px; }
          .grid th, .grid td { border: 1px solid #C0C0C0; padding: 5px; }
          .head { background-color: #E8E8E8; font-weight: bold; color: #FFF; }
          .alt { background-color: #E8E8E8; color: #000; }
        </style>
    </head>



    <body>
        <h1>Payment Schedule</h1>
        <h2>  </h2>

        <form method="post">
        <div id="grid">
            account: <input type="text" name="company" value="@Request["account"]" />
            Company: <select name="Company">
                     <option></option>   
                @foreach(var item in companies){
                    <option @(Request["Company"] == item.Company ? " selected=\"selected\"" : "")>@item.Company</option>
                }
            </select>
            <input type="submit" />

            @grid.GetHtml(
                tableStyle: "grid",
                headerStyle: "header",
                alternatingRowStyle: "alt",
                columns: grid.Columns(
                grid.Column(format: @<a href="~/EditDB?id=@item[0]">Edit</a>),
                grid.Column("Date", format: (item) => string.Format("{0:MMM dd yyyy}", item.Date) ),
                grid.Column("Company"),
                grid.Column("Account"),
                grid.Column("Payee"),
                grid.Column("Section"),
                grid.Column("Category"),
                grid.Column("Product"),
                grid.Column("Currency"),
                grid.Column("Amount"),
                grid.Column("FX"),
                grid.Column("USD"),
                grid.Column("Comments")                       
               )
            )
        </div>
        </form>
    </body>
</html>

    @section script{
        <script type="text/javascript">
           $(function(){
                $('th a, tfoot a').live('click', function() {
                    $('form').attr('action', $(this).attr('href')) ;
                    return false;
                });
            });
        </script>
    }

已修复-我已经更改了这部分:

 account: <input type="text" name="company" value="@Request["account"]" />

收件人:

 account: <input type="text" name="account" value="@Request["account"]" />