MVC Anonymous Class Transfer value learning

Source: Internet
Author: User

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 privaterepairsystemEntities db = newrepairsystemEntities();  // GET: TEST  publicActionResult Index()  {      varInfo = db.bom.ToList().Select(p => Tuple.Create(p.Bom_Brand, p.Bom_Model));      ViewBag.Info = Info;      returnView();  } 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.