c# - An object is not in a list after being added to a list -


I am developing an MVC 4 internet application in C # and having trouble adding one object to a list .

This is my book class:

  public class book {public book () {comments = new collection & lt; Comment & gt; (); } [Key] Public ID {Receive; Set; } Public string title {get; Set; } Public String Writer {get; Set; } Public String Username {get; Set; } Public identification & lt; Comment & gt; Comments {get; Set; }}  

Here is my comment class:

  public class comment {[key] public ID (get); Set; } Receive public string comment text { Set; } Public String Username {get; Set; }}  

Here's my method:

[authorize] [http post] [legitimate antifreeze token] create public action ranges (int id, comment) Comment) {if (ModelState.IsValid) {comment.username = us.GetCurrentlyLoggedInUserName (); Db.books.Where (b => BID == ID). FirstOver Default (). Comments.Add (comment); Db.SaveChanges (); Return Redirect Action ("Index", new {ID}); } View return (comment); }

This is my indexing method:

  Public Function Index (int id) {var commentsBookViewModel = new commentsViewModel (); CommentsBookViewModel.bookId = ID; CommentsbookviewModel.IsUser LogDidin = us.IsUserLoggedIn (); CommentsBookViewModel.loggedInUserName = us.GetCurrentlyLoggedInUserName (); Comments BookViewModel.comments = db.books.Where (b = & gt; bid == ID). First and last default (). notes. ToList (); See Return (commentsBookViewModel); }  

The comment has been added to the book's comment list after the method, and the index method is called, there is no comment in the list of comments books.

Can I help?

Thanks in advance


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -