Reputation: 7520
I have a page where a product appears on the right side and the user can add comment so i have a user control which gets all the comments and a small text area where user can add new comment for that product.
the link of the page is like
http://localhost/Product/TestComment/1
Where 1 indicates the id of the product and I have been hard coding my AddNote function below and fourth argument you see has been hard coded, but i need to pass that as the id of the product. How do i do this
AddNote(HttpContext.User.Identity.ToString(), txtComment, 1, DateTime.Now, true);
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddComment(string txtComment)
{
bool rst = _NotesService.AddNote(HttpContext.User.Identity.ToString(), txtComment, 1, DateTime.Now, true);
return RedirectToAction("TestComment");
}
Upvotes: 0
Views: 830
Reputation: 13083
To expand on mmcteam's answer, your controller action link should read as follows:
http://localhost/Product/AddComment/
it should be POST (as you already have it) and should have the following signature in controller:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddComment(string txtComment, int productId)
and you would need something like this in your view:
<%=Html.HiddenFor(model=>model.productId)%>
HTH
Upvotes: 1
Reputation: 1020
Add one more parameter to your Action and also add hidden field to your form with that parameter(id=1)
Upvotes: 0