MVC Controller returns entity to view

Source: Internet
Author: User

Objective

These days the VS12 updated to VS12 5, because found me before the 12 have a problem, no MVC, then from itellyou downloaded 12 update5 updated a bit. To tell the truth, from the development to the present, oneself just usually play with MVC+EF, contact project is not used. It is obvious that the present self and 12 years or even 13 years of their own than really is not a standard (blow yourself), that he is progress, but the extent of progress is not big, if the large should be like Daniel Close, in fact, far away from that place is far away ...

Body

Just do a test today and extract the data. MVC4 build a Web site, then build an EF class library, write an index view and a controller, and EF generates the corresponding model based on the database.

1, Eedle, create the context when the report does not have a XXX string , the prompt is very clear, EF Config does have, but the Web config is missing, then the EF configuration paste copied to the Web Config, and then OK.

2.

Then the view page gets the quote "no object ... ", and then try again and return the FirstOrDefault directly.

In fact, there is an ORM mechanism in the EF, so the data has been found to match the table entity, then LINQ to find out the IQuery collection, so to return an object also need to take out the first to return. View gets directly @model. Attribute, must also be forced to be named to view, @model entity name. A simple page will come out.

Summarize

It's not that you have to do anything, because we don't have to use everything in our work. But in time to use their own, but also to understand some of the principles of this thing, in the understanding of the principle of the situation in the use of him, the process of learning will be quickly started. Although this is a very simple thing today, I'm just sharing my feelings with the little partner that MVC has been using, and I have no idea. Remember a while ago (4, 5 months ago) to find a job, there is a company interview, personnel face me, then the director did not interview let personnel asked me to use MVC, I said no. Then there is no interview me, I want to say, there is no one thing is used by everyone, did you use it from the beginning, all things are never to have. No one is born to be a genius.

Believe Yourself,never give up

MVC Controller returns entity to view

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.