У меня есть приложение для выставления счетов с несколькими функциями поиска (поиск счетов по типу, статусу и идентификатору клиента).Мне нужно реализовать поиск только по году, и дополнительный поиск по датчику (для двух отдельных просмотров).Может кто-нибудь мне помочь?
Вот мой код:
Контроллер:
public ActionResult Search(InvoiceViewModel invoiceViewModel)
{
LoadStatus();
LoadInvoiceType();
invoiceViewModel.CustomerModelList = customerRepository.All();
invoiceViewModel.InvoiceList = invoiceRepository.All()
.WhereIf(!String.IsNullOrEmpty(invoiceViewModel.InvoiceCode),x=> x.InvoiceCode == invoiceViewModel.InvoiceCode)
.WhereIf(!String.IsNullOrEmpty(invoiceViewModel.Type), x => x.Type == invoiceViewModel.Type)
.WhereIf(!String.IsNullOrEmpty(invoiceViewModel.Status), x => x.Status == invoiceViewModel.Status)
.WhereIf(invoiceViewModel.CustomerId.HasValue, x => x.CustomerId == invoiceViewModel.CustomerId.Value)
.Include(x => x.CustomerModel).OrderBy(x => x.Id).ToList();
invoiceViewModel.count = invoiceViewModel.InvoiceList.Count();
return View("Index",invoiceViewModel);
}
Index.cshtml:
<script>
$(function () {
$(".mydatepicker").datepicker();
$(document).on('click', '.panel-heading span.clickable', function (e) {
var $this = $(this);
if (!$this.hasClass('panel-collapsed')) {
$this.parents('.panel').find('.panel-body').slideUp();
$this.addClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
} else {
$this.parents('.panel').find('.panel-body').slideDown();
$this.removeClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
}
});
});
</script>
@using (Html.BeginForm("Search", "Invoice", FormMethod.Get))
{
<div class="form-horizontal">
<div class="col-md-2">
@Html.EditorFor(model => model.InvoiceCode, new { htmlAttributes = new { @class = "form-control", @id = "InvoiceCode", @placeholder = "Invoice code" } })
</div>
<div class="col-md-2">
@Html.DropDownListFor(model => model.CustomerId, new SelectList(Model.CustomerModelList, "Id", "Name"), "select Customer", new { @class = "form-control", @id = "CustomerId" })
</div>
<div class="col-md-2">
@Html.DropDownListFor(model => model.Type, ViewData["invoicetype"] as List<SelectListItem>, "select type", new { @class = "form-control", @id = "Type" })
</div>
<div class="col-md-2">
@Html.DropDownListFor(model => model.Status, ViewData["country"] as List<SelectListItem>, "select status", new { @class = "form-control", @id = "Status" })
</div>
<div class="col-md-1">
<div>
@Html.EditorFor(model => model.DateFrom, new { htmlAttributes = new { @class = "form-control mydatepicker", @id = "DateFrom", @placeholder = "Date From" } })
</div>
</div>
<div class="col-md-1">
<div>
@Html.EditorFor(model => model.DateTo, new { htmlAttributes = new { @class = "form-control mydatepicker", @placeholder = "Due Date", @id = "DueDate" } })
</div>
</div>
<div class="col-md-1">
<input type="submit" style="width: 100%" id="btnSubmit" value="Search" class="btn btn-primary" />
</div>
<div class="col-md-1">
<input type="submit" style="width: 100%" id="btnSubmit" value="Reset" class="btn btn-primary" />
</div>
</div>
}