在ASP.NET MVC我使用的HTML幫助如何使用Html.BeginForm()傳入ID?
Html.BeginForm("ActionName", "Controller", FormMethod.Post);
但我需要發佈到:/控制器/動作/ 23434
如何傳遞的ID?
在ASP.NET MVC我使用的HTML幫助如何使用Html.BeginForm()傳入ID?
Html.BeginForm("ActionName", "Controller", FormMethod.Post);
但我需要發佈到:/控制器/動作/ 23434
如何傳遞的ID?
馬特應該工作正常。如果你還在傳遞FormMethod.Post
,不過,你需要做的是這樣的:
Html.BeginForm("action","controller", new { Id = 12345 }, FormMethod.Post);
逆轉的第三和第四個參數將導致Id
被視爲一個屬性,而不是路由值。
Html.BeginForm("action", "controller", new {Id = 12345})
Html.BeginForm("action", "controller", new { id = ViewBag.FileID },
FormMethod.Post, new { id = "feedbackform" })
至於查詢字符串,我不知道該怎麼做。當然,查詢是一個get,並破壞FormMethod.Post
的整個目的。我的意思是,如果你想查詢字符串數據,你可以使用FormMethod.Get
,這可能是你正在尋找的。
此外,您可以避免html.beginform
並使用表單標籤手動執行querystring,get + post。
第三,如果你使用的是形式,你可以做一個隱藏字段:
[input type=hidden name="type" value="golden"]
然後,當提交按鈕被按下的值被正確地傳遞一個表單變量。
不起作用,它向表單標籤添加了一個屬性。 – mrblah 2009-05-18 15:40:50
檢查參數名稱routeValues - 確保您使用的不是htmlAttributes。 – 2009-05-18 15:44:02