Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i binded webgrid with a single model data in a controller .
but how do i bind the webgrid with data of two models .

What I have tried:

@model IEnumerable<WebApplication4.Models.Register>

@{
    ViewBag.Title = "getgrid";
    WebGrid gridview = new WebGrid(Model, ajaxUpdateContainerId : "ajaxgrid");
}

<h2>getgrid</h2>

@gridview.GetHtml(columns: new[]

{
gridview.Column("ID"),
gridview.Column("FirstName"),
gridview.Column("LastName"),
gridview.Column("CH",format: @<text><input name="chkbox"
                                  type="checkbox"/></text>),
}

            )


Public ActionResult webgridview(){
list<register> li=new list<register>();
return view(li);
}


here above i binded register class to grid but i want to bind other class details also .am not finding the proper answer for that.
Posted
Updated 21-Jun-18 2:44am
Comments
F-ES Sitecore 21-Jun-18 8:44am    
You can't. However google "mvc bind two models" for workarounds, this is a very frequently asked question.

1 solution

You can only pass a single model to a view. Period. End of story.

So, wrap your model classes with another class and pass this new class to the view instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900