asp.net mvc 4 - ModelContext + the "query" returns nothing -


i'm beginner in asp.net mvc4.

i've created model table in data base. i've 2 entry in table.

i try send entry in controller modelcontext returns null. here code:

my controller:

enter code herepublic class homecontroller : controller {     //connection à la table     private annoncemodelcontext db = new annoncemodelcontext();      public actionresult index()     {         annoncemodel last_annonce = db.annonces.find(2);         if (last_annonce == null)         {             viewbag.message = "pas d'annonce pour le moment";             return view();         }         else         {             return view(last_annonce);         }     } 

my views:

@model wiki_bird.models.annoncemodel <section id="annonce" class="content-wrapper">         <h1>annonce</h1>         <p>            @viewbag.message             <br />            @html.displayfor(model => model.titre)         </p>     </section> 

last_annonce null table "annonce" in database not empty!

i hope can me! sorry bad english i'm not english.

regards,

sushi


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -