从按钮单击MVC调用函数

时间:2015-11-11 11:41:52

标签: javascript c# asp.net-mvc linq razor

我有一个列表视图,我想用下拉列表和一些复选框来过滤它。 See image

这是我视图中的代码:

<div>
    <table border=0 id="idpagetitle">
        <tr>
            <td style="width: 480px; width:330px">
                <center>
                    <font color=black>
                        <b>Show:</b>
                    </font>
                    <select id="location_id" style="width:200px">
                        <option value="default"> - </option>
                        <option value="all" selected>All Locations</option>
                        <option value='23'>Location X</option>
                        <option value='15'>Location Y</option>
                    </select>
                </center>
            </td>
            <td class="pagetitlelabel" width="400">
                <table border=0>
                    <tr>
                        <td><input type="checkbox" id="all"> All</td>
                        <td><input type="checkbox" id="active"> Active</td>
                        <td><input type="checkbox" id="paid"> Paid</td>
                        <td><input type="checkbox" id="receivables"> Receivables</td>
                    </tr>
                    <tr>
                        <td><input type="checkbox" id="curmonth"> Current Month</td>
                        <td><input type="checkbox" id="inactive"> Inactive</td>
                        <td><input type="checkbox" id="unpaid"> Unpaid</td>
                        <td><input type="checkbox" id="payables"> Payables</td>
                    </tr>
                </table>
            </td>
            <td><input type="submit" class="smallbutton" id="FilterClick" onclick="FilterClick(location_id, active, paid, receivables, curmonth, inactive, unpaid, payables)" value="Filter" /></td>
            <td><input type="submit" class="smallbutton" name="cmdxls" onclick="cmdexcel()" value="All to Excel"></td>
        </tr>
    </table>
</div>

这是我控制器中的代码:

public ActionResult FilterClick(int location, bool active, bool paid, bool receivables, bool curmonth, bool inactive, bool unpaid, bool payables, bool all)
        {
            LeaseFilterModel filter = new LeaseFilterModel();
            filter.Location = location;
            filter.Active = active;
            filter.Paid = paid;
            filter.Receivables = receivables;
            filter.CurrentMonth = curmonth;
            filter.Inactive = inactive;
            filter.Unpaid = unpaid;
            filter.Payables = payables;
            filter.All = all;

            LMWEBLINQDataContext leases = new LMWEBLINQDataContext();
            var leaseList = (from l in leases.tblfLeaseDetails
                             join v in leases.tblvVendors on l.Vendor_ID equals v.Vendor_ID
                             join c in leases.tblvCounties on l.County_ID equals c.County_ID
                             join a in leases.tblfAuthorizations on l.Lease_Detail_ID equals a.Lease_Detail_ID
                             join t in leases.tblvLineTypes on l.Line_Type_ID equals t.Line_Type_ID
                             where l.Location_ID == filter.Location
                             select new
                             {
                                 l.Lease_Detail_ID,
                                 l.Lease_ID,
                                 l.XRef_Lease_ID,
                                 v.Vendor_Name,
                                 l.Description,
                                 c.County,
                                 l.Amount,
                                 l.Payment_Due_Date,
                                 a.Authorized,
                                 t.Line_Type
                             }).Distinct().ToList().ToNonAnonymousList(new List<LeaseViewModel>()).Take(10);
            return View(leaseList);
        }

问题: 当我运行应用程序并单击按钮时,它根本不会触发任何内容。请帮我弄清楚我做错了什么。

1 个答案:

答案 0 :(得分:1)

对于服务器端方法,您需要使用BeginForm帮助程序。因此,最好的方法是将您的观点改为:

var test = 777;