ASP.NET MVC3 simple commenting system --- displaying the comments -


trying add commenting system pages. able scaffold list view for comments on each page.

i thought use scaffold code , place partialview changing return value partialview(db.comments.tolist()); , viewresult actionresult.

it breaks @ @for (item in model) {....} null reference exception error.

so...any idea on how this? ex: commenting system anywhere.

    @model ienumerable<_2nditeration.models.comment>  @{     viewbag.title = "messages"; }  <h2>messages</h2>  <p>     @html.actionlink("create new", "create") </p> <table>     <tr>         <th>             uname         </th>         <th>             email         </th>         <th>             subject         </th>         <th>             referrer         </th>         <th>             created         </th>         <th>             comment         </th>         <th></th>     </tr> @*breaks here!!!!!!with null reference exception on model object*@ @foreach (var item in model) {     <tr>         <td>             @html.displayfor(modelitem => item.uname)         </td>         <td>             @html.displayfor(modelitem => item.email)         </td>         <td>             @html.displayfor(modelitem => item.subject)         </td>         <td>             @html.displayfor(modelitem => item.referrer)         </td>         <td>             @html.displayfor(modelitem => item.created)         </td>         <td>             @html.displayfor(modelitem => item.comment)         </td>         <td>             @html.actionlink("edit", "edit", new { id=item.id }) |             @html.actionlink("details", "details", new { id=item.id }) |             @html.actionlink("delete", "delete", new { id=item.id })         </td>     </tr> }  </table> 

the controller action

public class commentscontroller : controller {     private dbentity db = new dbentity();      //     // get: /comments/read     public actionresult readcomments()     {         return partialview(db.comments.tolist());     } 

and model

using system; using system.collections.generic; using system.linq; using system.web; using system.componentmodel.dataannotations;  namespace _2nditeration.models {     public class comment     {         public int id { get; set; }         [display ( name = "name")]         public string uname { get; set; }         [display(name = "email address")]         public string email { get; set; }         [display(name = "subject")]         public string subject { get; set; }         public string referrer { get; set; }         public datetime? created { set; get; }         [required]         [display(name = "comment")]         public string comment { get; set; }     } } 


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -