点击MVC按钮调用函数

本文关键字:函数 调用 按钮 MVC 点击 | 更新日期: 2023-09-27 18:21:26

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

这是我认为的代码:

<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);
        }

问题:当我运行应用程序并单击按钮时,它根本不会触发任何事情。请帮我找出我做错了什么。

点击MVC按钮调用函数

对于服务器端方法,您需要使用BeginForm助手。因此,最好的方法是将你的观点改变为这样的东西:

                @using (Html.BeginForm("yourmethodname", "yourcontrollername", new { id = "FilterClick" }, FormMethod.post,null ))
            {
                <input type="submit" class="smallbutton" id="FilterClick"  value="Filter" />                }