在ASP.NET MVC中,我使用的是helper
Html.BeginForm("ActionName", "Controller", FormMethod.Post);
但是我需要发送到: /controller/action/23434
如何传入ID?
发布于 2009-05-18 15:49:31
Matt的应该会工作得很好。但是,如果您仍在传递FormMethod.Post
,则需要这样做:
Html.BeginForm("action","controller", new { Id = 12345 }, FormMethod.Post);
颠倒第三个和第四个参数将导致Id
被视为属性而不是路由值。
发布于 2009-05-18 15:35:49
Html.BeginForm("action", "controller", new {Id = 12345})
发布于 2013-10-10 02:39:43
Html.BeginForm("action", "controller", new { id = ViewBag.FileID },
FormMethod.Post, new { id = "feedbackform" })
至于查询字符串,?type=golden
,我不知道该怎么做。当然,查询是一种get,它破坏了FormMethod.Post
的全部用途。我的意思是,如果你想要查询字符串数据,你可以使用FormMethod.Get
,这可能就是你想要的。
此外,您可以避免使用html.beginform
,而使用表单标记手动执行查询字符串get + post。
第三,如果你使用的是表单,你可以创建一个隐藏字段:
[input type=hidden name="type" value="golden"]
然后,当按下submit按钮时,该值将作为表单变量正确传递。
https://stackoverflow.com/questions/878330
复制相似问题