c# - Null id value in MVC 4 Controller -


I am developing an MVC 4 internet application and I'm having trouble after creating an object.

Here is the code where the error is happening:

[Authorize] [http post] [validAnnetGreativein] Public actionbelt (int id, comment comment) {if (ModelState .IsValid) {book book = Db.books.Where (b = & gt; BID == ID). first (); Comment. Username = us.GetCurrentlyLoggedInUserName (); Book.comments.Add (comment); Db.SaveChanges (); Return Redirect Action ("Index", ID); } View return (comment); }

Here is an index action result:

  Public Action Result Index (Ent ID) {var CommentbookViewModel = New CommentsWellModel (); 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); } Here is an error:  

The parameter dictionary contains a blank entry for the parameter 'id' for the non-empty type 'System.Int32'. In the 'System.Web.Mvc.ActionResult Index (' Int32) '' BookApplication.Controllers.CommentController '' an optional parameter should be a reference type, a faucet type, or be declared as an optional parameter. Parameter Name: Parameter

If I put a break point on this line:

  return redirection action ("index", id);  

is the value of variable id , and is not empty, still the error still occurs.

Can I please do this?

Thanks in advance

I try to pass it along with something like this Will do

Returns Direct Reaction ("index", new {id = id});


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 -