0

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Yes for HiddenFor but you don't have to use HiddenFor, you can use Html.Hidden().
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.