How to pass in ID with Html.BeginForm()?

后端 未结 3 1739
难免孤独
难免孤独 2020-12-28 13:44

In ASP.NET MVC I\'m using the HTML helper

Html.BeginForm(\"ActionName\", \"Controller\", FormMethod.Post);

But I need to post to: /control

3条回答
  •  自闭症患者
    2020-12-28 14:16

    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.

    Additionally, you can avoid html.beginform and do the querystring, get + post, manually with a form tag.

    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.

提交回复
热议问题