Shortly after contacting the MVC+EF framework, it is always confusing whether the controller can and how to pass anonymous class data to the view. Baby said it is very annoying to create a new entity class, query a little different to build an entity class is not very troublesome, so take advantage of the sun, the weekend sleep to natural wake up after trying to have been in the blog park to see the realization of the way: the wise Shenwu of the tuple class, the first time to Microsoft admiration. So make the following record, convenient to use after yourself. The great God does not squirt me, the first time the baby writes the blog.
First describe the function I want to implement: from the controller background query some data, through anonymous class storage, the view front-end traversal output. The original implementation process is as follows:
Controller section:
12345678 |
private
repairsystemEntities db =
new
repairsystemEntities();
// GET: TEST
public
ActionResult Index()
{
var
Info = db.bom.ToList().Select(p => Tuple.Create(p.Bom_Brand, p.Bom_Model));
ViewBag.Info = Info;
return
View();
}
|
View section:
<table class= "Table Table-hover" > <tbody> @foreach (var item in Viewbag.info) { <tr > <td>@ (item. ITEM1) </td> </tr> } </tbody></table>
MVC Anonymous Class Transfer value learning