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.
FilterClick()function (or are you thinking that what you have done calls the server method - -which it does not)onclickis client side code. If you want to call a server method, then you either need to do a redirect usinglocation.href=yourUrlor 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 returnPartialView(notView) or are you wanting to display a new page - in which case just use a form and submit it.