tags:

views:

32

answers:

2

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");
}
A: 

Add one more parameter to your Action and also add hidden field to your form with that parameter(id=1)

mmcteam.com.ua
+1  A: 

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

mare
do i need mvc 2 for this?
Pinu
Yes for HiddenFor but you don't have to use HiddenFor, you can use Html.Hidden().
mare