我的模特
public IEnumerable GetTaskDetails()
{
var taskdata = (from d in edc.TaskTBs
join d1 in edc.TaskToUserTBs on d.TaskID equals d1.TaskID
where d.IsActive == true
select new
{
d.ProjectTB.ProjectName,
d.DBName,
d.Description,
d.FromDate,
d.ToDate,
d1.RegistrationTB.Name,
d1.RegistrationTB.Email
}).AsEnumerable().ToList();
//var taskdata = (from d in edc.TaskTBs
// select d).AsEnumerable().ToList();
return taskdata;
}
我的观点
<div>
@Html.Partial("PartialView/_TaskDetails", Model.Tasklist)
</div>
我的部分视图
@{
var grid1 = new WebGrid(source: Model, canPage: true,
defaultSort: "DBName",
canSort: true,
rowsPerPage: 5, selectionFieldName: "selectedRow", ajaxUpdateContainerId: "webgrid");
grid1.Pager(WebGridPagerModes.All);
}
<div id="grid">
<div style="margin-left: 75px;">
@grid1.GetHtml(
tableStyle: "webgrid",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style",
columns: grid1.Columns(
//grid1.Column("Name"),
//grid1.Column("ProjectName"),
grid1.Column("DBName"),
grid1.Column("Description"),
grid1.Column("FromDate"),
grid1.Column("ToDate")
//grid1.Column("Email")
)
)
</div>
我是MVC的新手。 我想将 taskdata 传递给部分视图以显示网格。 当我通过评论 taskdata 时,它工作正常但当我通过它时会给我错误
错误
The best overloaded method match for 'System.Web.Helpers.WebGrid.WebGrid(System.Collections.Generic.IEnumerable<object>, System.Collections.Generic.IEnumerable<string>, string, int, bool, bool, string, string, string, string, string, string, string)' has some invalid arguments
答案 0 :(得分:1)
调用您的局部视图
<div>
@Html.Partial("PartialView/_TaskDetails", GetTaskDetails())
</div>
您的观点
@model IEnumerable<object>
@{
var grid1 = new WebGrid(source: Model, canPage: true,
...
}