0

I have a list view, and I want to filter it with a drop-down and some checkboxes. See image

This is the code in my view:

<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>

This is the code in my controller:

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

Problem: When I run the application and click the button it simply doesn't trigger anything. Please help me to find out what I am doing wrong.

4
  • 3
    You need to show you javascript for the FilterClick() function (or are you thinking that what you have done calls the server method - -which it does not) Commented Nov 11, 2015 at 11:44
  • FilterClick() should be defined in a javascript code? I add it in my view? I thought the controller was the right place to define it Commented Nov 11, 2015 at 11:49
  • onclick is client side code. If you want to call a server method, then you either need to do a redirect using location.href=yourUrl or you need ajax to post the values to the server method. It's not clear what your intention is here. Are you wanting to display the view returned by your server method on the same page - in which vase you should return PartialView (not View) or are you wanting to display a new page - in which case just use a form and submit it. Commented Nov 11, 2015 at 11:54
  • In addition to "stephen's" comment your parameters are also mismatch with your server side code. you need to show your javascript code Commented Nov 11, 2015 at 12:36

1 Answer 1

1

For Server side method you need using BeginForm helper. So the best approach is changing you view to something like this:

                @using (Html.BeginForm("yourmethodname", "yourcontrollername", new { id = "FilterClick" }, FormMethod.post,null ))
            {
                <input type="submit" class="smallbutton" id="FilterClick"  value="Filter" />                }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Hadee! That works! I also used this article as reference: asp.net/mvc/overview/getting-started/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.