我想将我的pagedlist
类型的属性传递给局部视图。但我收到此错误
传递到字典中的模型项的类型为ModelViewPaging.Models.LogMasterViewModel,但是此字典需要类型为PagedList.IPagedList1 [ModelViewPaging.Models.log_master]的模型项。
这是我的模型课
public partial class log_master
{
[Key]
public long log_id { get; set; }
[Display(Name = "User")]
public string logged_user { get; set; }
[Display(Name = "Process Name")]
public string controller_name { get; set; }
[Display(Name = "Action Name")]
public string action_name { get; set; }
[Display(Name = "Task")]
public string log_msg { get; set; }
[Display(Name = "DateTime")]
public Nullable<System.DateTime> log_time { get; set; }
public string log_route { get; set; }
public int? PageCount { get; set; }
public int? PageNumber { get; set; }
}
我创建了一个用于过滤的视图模型,并在此视图模型中声明了一个分页列表
public class LogMasterViewModel
{
[Key]
public int lmvm_id { get; set; }
[Display(Name = "Personal Number")]
public string pNumber { get; set; }
[Display(Name = "Process Name")]
public string ProcessName { get; set; }
[Display(Name = "From"), DataType(DataType.Date),
DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode =
true), Required(ErrorMessage = "Please Select From Date")]
public Nullable<System.DateTime> FromDate { get; set; }
[Display(Name = "To"), DataType(DataType.Date),
DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode =
true), Required(ErrorMessage = "Please Select To Date")]
public Nullable<System.DateTime> ToDate { get; set; }
public IPagedList<log_master> LogList { get; set; }
}
这是我的控制器代码。我想将viewmodel的所有值传回给pagedlist进行查看。
public ActionResult Index(LogMasterViewModel lmvm, int? Page_no)
{
TestEntities db = new Models.TestEntities();
try
{
// Getting list of processes from error log
ViewBag.ProcessList = new SelectList(GetLogProcess() as
List<SelectListItem>, "Value", "Text");
if (lmvm.FromDate.HasValue && lmvm.ToDate.HasValue)
{
int pageSize = 10;
int pageIndex = 1;
pageIndex = Page_no.HasValue ? Convert.ToInt32(Page_no) : 1;
var result = (from lm in db.log_master
where DbFunctions.TruncateTime(lm.log_time) >= DbFunctions.TruncateTime(lmvm.FromDate) &&
DbFunctions.TruncateTime(lm.log_time) <= DbFunctions.TruncateTime(lmvm.ToDate)
select lm).ToList();
if (!string.IsNullOrEmpty(lmvm.pNumber))
result = result.Where(x => x.logged_user.ToUpper() == lmvm.pNumber.ToUpper()).ToList();
if (!string.IsNullOrEmpty(lmvm.ProcessName))
result = result.Where(x => x.controller_name.ToUpper() == lmvm.ProcessName.ToUpper()).ToList();
lmvm.LogList = result.ToPagedList(pageIndex, pageSize);
}
catch (Exception ex)
{
Response.Write(ex.InnerException != null ? ex.InnerException.Message.ToString() : ex.Message.ToString());
}
return View(lmvm);
}
在我看来,我这样称呼局部视图。
<div id="logdiv">
@Html.Partial("PartialReportView", Model.LogList)
</div>
局部视图
@model PagedList.IPagedList<ModelViewPaging.Models.log_master>
@using PagedList.Mvc