开发者

asp.net mvc form add comment

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 = _Notes开发者_如何学运维Service.AddNote(HttpContext.User.Identity.ToString(), txtComment, 1, DateTime.Now, true);
    return RedirectToAction("TestComment");
}


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜