Amol
Amol

Reputation: 1461

Pass IEnumerable list to partial view contains WebGrid

My Model

   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;
    }

My View

        <div>
            @Html.Partial("PartialView/_TaskDetails", Model.Tasklist)
        </div>

My Partial View

@{       
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>

I am New in MVC . I want to pass taskdata to Partial view to display grid. When I pass Commented taskdata it works Fine but When I pass this it will give me error

Error

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

Upvotes: 0

Views: 1120

Answers (1)

Igor Semin
Igor Semin

Reputation: 2496

Calling your partial view

    <div>
        @Html.Partial("PartialView/_TaskDetails", GetTaskDetails())
    </div>

Your view

@model IEnumerable<object>

@{       
     var grid1 = new WebGrid(source: Model, canPage: true,
     ...
}

Upvotes: 1

Related Questions