2010-05-03 59 views
0

我有一个页面,产品出现在右侧,用户可以添加注释 ,所以我有一个用户控件,它获取所有评论和一个小文本区域,其中用户可以添加 该产品的新评论。asp.net mvc表单添加注释

页面的链接就像是

http://localhost/Product/TestComment/1

其中1表示产品的ID和我一直在硬编码我AddNote功能如下 ,你会看到已经硬编码的第四个参数,但我需要通过该产品的编号为 。我该怎么做

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

回答

1

要扩大mmcteam的答案,你的控制器操作链接应如下:

http://localhost/Product/AddComment/

应该是POST(因为你已经拥有它),并应在控制器的以下特征:

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult AddComment(string txtComment, int productId) 

,你需要在你的看法是这样的:

<%=Html.HiddenFor(model=>model.productId)%> 

HTH

+0

我需要MVC 2吗? – Pinu 2010-05-03 15:41:40

+0

是的,对于HiddenFor,但你不必使用HiddenFor,你可以使用Html.Hidden()。 – mare 2010-05-03 16:01:22

0

一个参数添加到您的行动,也隐藏字段的形式与参数添加(ID = 1)