【问题标题】:MVC Get data from View to ControllerMVC 从 View 获取数据到 Controller
【发布时间】:2013-08-30 07:38:41
【问题描述】:
@using (Html.BeginForm("testingMethod","test",FormMethod.Get)) {
@Html.AntiForgeryToken()

@foreach (var item in Model) {
    @Html.DropDownList("dropDown_"+item.ConfigCode+"_ListName", (IEnumerable<SelectListItem>)ViewData["dropDown_"+item.ConfigCode])
}
                    .
                    .
                    .
                    .
}
<input type="submit" value="Save" />

基于上面的代码,我成功调用了“testController”中的方法“testingMethod”,它返回了一个URL:

http://localhost:59512/test/testing?__RequestVerificationToken=xxxxxxx&dropDown_KKK=3

在我的 ActionResult "testingMethod" 中,我需要得到这个 dropDown_KKK 值,它是 3。我可以知道我应该在我的方法中做什么吗?我试过编辑 testingMethod 如下:

public ActionResult testing(FormCollection collection){
    Debug.WriteLine(" ======= " + collection.GET("dropDown_KKK"));

}

基于其他帖子,它应该可以工作,但在 collection.GET 处发生错误,它说 System.Web.MvC.FormCollection 不包含 GET 的定义,并且没有扩展方法 'GET' 接受第一个参数 blablabla...

【问题讨论】:

    标签: asp.net-mvc razor view controller actionresult


    【解决方案1】:

    你可以使用:

    collection["name"]
    

    name 应该是下拉列表的名称。

    【讨论】:

    • 里面什么都没有,但正如我所说,从 URL 我看到“3”作为值,还有其他方法可以从 URL 访问值吗?
    • 你可以使用Request.QueryString["dropDown_KKK"]
    猜你喜欢
    • 1970-01-01
    • 2019-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    相关资源
    最近更新 更多