GridMvc不会过滤所有字段

时间:2018-01-08 21:07:02

标签: asp.net-mvc-4 filtering

我在asp.net mvc 4.5中使用了GridMvc。除了几个字符串外,所有过滤器都在工作。我看不出这些字符串和正在运行的字符串之间有什么区别。我错过了什么?

查看     @model Infotech.Coverpools.Portal.Tintaglia.Web.Models.AccountHistoryVM     @using GridMvc.Html

<h2>Account History</h2>    
@Html.Grid(Model.Records).Columns(columns =>
{
    columns.Add(m => m.CustomerNo_).Titled("Account #").Filterable(false); 
    columns.Add(m => m.PostingDate).Format("{0:MM/dd/yyyy}").SetWidth(100).Titled("Order Date").Filterable(true); //filter
    columns.Add(m => m.DocumentType).Titled("Type").Filterable(true); //filters
    **columns.Add(m => m.DocumentNo_).Titled("Document #").Filterable(true); //doesn't filter**
    columns.Add(m => m.Description).Titled("Description").SetWidth(300).Filterable(true); //filters
    **columns.Add(m => m.ExternalDocumentNo_).Titled("Memo").SetWidth(300).Filterable(true); //doesn't filter**
    columns.Add(m => m.Amount).Format("{0:$#,###.00}").Titled("Original Amount").SetWidth(200).Filterable(true); //filters
    columns.Add(m => m.RemainingAmount).Format("{0:$#,###.00}").SetWidth(100).Titled("Remaining Amount").Filterable(true); //filters
    columns.Add(m => m.DueDate).Format("{0:MM/dd/yyyy}").Titled("Due Date").Filterable(true); 
}).WithPaging(20).Sortable(true) //filters
<script src="~/Scripts/gridmvc.js"></script>

模型

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;

namespace Infotech.Coverpools.Portal.Tintaglia.CodeFirst.Models
{
    [Table("CustLedgerEntry")]
    public class CustLedgerEntry
    {
        [Key]
        [Column(Order = 0)]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int EntryNo_ { get; set; }

        [StringLength(20)]
        public string CustomerNo_ { get; set; }

        public DateTime PostingDate { get; set; }

        [StringLength(20)]
        public string DocumentType { get; set; }


        [StringLength(20)]
        public string DocumentNo_ { get; set; }

        [StringLength(50)]
        public string Description { get; set; }

        [StringLength(35)]
        public string ExternalDocumentNo_ { get; set; }

        [DataType(DataType.Currency)]
        public decimal Amount { get; set; }

        [DataType(DataType.Currency)]
        public decimal RemainingAmount { get; set; }

        [DataType(DataType.Date)]
        public DateTime DueDate { get; set; }

        [DataType(DataType.DateTime)]
        public DateTime DatetoWebSales { get; set; }

        [StringLength(3)]
        public string Open { get; set; }
    }
}

控制器

public ActionResult AccountHistory()
{

    var dealerId = db.UserProfiles.Where(d => d.UserName.Equals(User.Identity.Name)).Select(d => d.CustomerId).FirstOrDefault();

    var vm = new AccountHistoryVM();
    vm.Records = db.CustLedgerEntries.ToList().Where(x => x.CustomerNo_.Equals(dealerId, StringComparison.OrdinalIgnoreCase));

    var datetoweb = db.CustLedgerEntries.FirstOrDefault(m => m.DatetoWebSales != null);
    vm.LastUpdatedDate = datetoweb.DatetoWebSales;
    return View(vm);
}

1 个答案:

答案 0 :(得分:0)

您好我刚刚从模型和网格中删除了下划线(_),现在它正常工作。

  

模型

Grid

  

网格

    <div class="container">
@Html.Grid(Model).Columns(columns =>
{
    columns.Add(m => m.CustomerNo_).Titled("Account #").Filterable(false);
    columns.Add(m => m.PostingDate).Format("{0:MM/dd/yyyy}").SetWidth(100).Titled("Order Date").Filterable(true); //filter
    columns.Add(m => m.DocumentType).Titled("Type").Filterable(true); //filters
    columns.Add(m => m.DocumentNo).Titled("Document").Filterable(true); //doesn't filter**
    columns.Add(m => m.Description).Titled("Description").SetWidth(300).Filterable(true); //filters
    columns.Add(m => m.ExternalDocumentNo).Titled("Memo").SetWidth(300).Filterable(true); //doesn't filter**
    columns.Add(m => m.Amount).Format("{0:$#,###.00}").Titled("Original Amount").SetWidth(200).Filterable(true); //filters
    columns.Add(m => m.RemainingAmount).Format("{0:$#,###.00}").SetWidth(100).Titled("Remaining Amount").Filterable(true); //filters
    columns.Add(m => m.DueDate).Format("{0:MM/dd/yyyy}").Titled("Due Date").Filterable(true);
}).WithPaging(20).Sortable(true) 
    </div>
  

输出

enter image description here