In ASP.NET MVC I'm using the HTML helper
在ASP。我正在使用HTML助手
Html.BeginForm("ActionName", "Controller", FormMethod.Post);
But I need to post to: /controller/action/23434
但是我需要发邮件到:/controller/action/23434
How do I pass in the ID?
我如何传递ID?
3 个解决方案
#1
62
Matt's should work fine. If you are still passing in FormMethod.Post
, though, you need to do it like this:
马特的应该不错。如果您仍在传递FormMethod。不过,你需要这样做:
Html.BeginForm("action","controller", new { Id = 12345 }, FormMethod.Post);
Reversing the third and fourth parameters will result in the Id
being treated as an attribute instead of a route value.
反转第三和第四个参数将导致Id被视为属性而不是路由值。
#2
10
Html.BeginForm("action", "controller", new {Id = 12345})
Html。BeginForm(“action”、“controller”、new {Id = 12345})
#3
7
Html.BeginForm("action", "controller", new { id = ViewBag.FileID },
FormMethod.Post, new { id = "feedbackform" })
As for the querystring, ?type=golden
, I don't know how to do that. Of course, a querysting is a get, and undermines the whole purpose of FormMethod.Post
. I mean, you could use FormMethod.Get
, if you want querystring data, and this might be what you are looking for.
对于querystring, ?type=golden,我不知道怎么做。当然,查询是get,并破坏FormMethod.Post的整个目的。你可以用FormMethod。Get,如果你想要查询字符串数据,这可能就是你要找的。
Additionally, you can avoid html.beginform
and do the querystring, get + post, manually with a form tag.
此外,还可以避免使用html。beginform和执行querystring、get + post,使用表单标记手动执行。
Thirdly, if you are using the form, you can make a hidden field:
第三,如果使用表单,可以创建一个隐藏字段:
[input type=hidden name="type" value="golden"]
Then, when the submit button is pressed the value is passed properly as a form variable.
然后,当按下submit按钮时,值作为表单变量被正确地传递。
#1
62
Matt's should work fine. If you are still passing in FormMethod.Post
, though, you need to do it like this:
马特的应该不错。如果您仍在传递FormMethod。不过,你需要这样做:
Html.BeginForm("action","controller", new { Id = 12345 }, FormMethod.Post);
Reversing the third and fourth parameters will result in the Id
being treated as an attribute instead of a route value.
反转第三和第四个参数将导致Id被视为属性而不是路由值。
#2
10
Html.BeginForm("action", "controller", new {Id = 12345})
Html。BeginForm(“action”、“controller”、new {Id = 12345})
#3
7
Html.BeginForm("action", "controller", new { id = ViewBag.FileID },
FormMethod.Post, new { id = "feedbackform" })
As for the querystring, ?type=golden
, I don't know how to do that. Of course, a querysting is a get, and undermines the whole purpose of FormMethod.Post
. I mean, you could use FormMethod.Get
, if you want querystring data, and this might be what you are looking for.
对于querystring, ?type=golden,我不知道怎么做。当然,查询是get,并破坏FormMethod.Post的整个目的。你可以用FormMethod。Get,如果你想要查询字符串数据,这可能就是你要找的。
Additionally, you can avoid html.beginform
and do the querystring, get + post, manually with a form tag.
此外,还可以避免使用html。beginform和执行querystring、get + post,使用表单标记手动执行。
Thirdly, if you are using the form, you can make a hidden field:
第三,如果使用表单,可以创建一个隐藏字段:
[input type=hidden name="type" value="golden"]
Then, when the submit button is pressed the value is passed properly as a form variable.
然后,当按下submit按钮时,值作为表单变量被正确地传递。