问题描述
亲爱的,
如何将视图中的值传递给控制器,即
我有一个静态下拉列表,我创建如下。
1)控制器代码
var list = new SelectList( new []
{
new {ID = 1, Name = name1},
new {ID = 2,Name = name2},
new {ID = 3,Name = name3},
},
ID, 名称, 1 );
ViewData [ list] = list;
2)在我的视图中,我按如下方式绑定Dropdown:
@ Html.DropDownList(list,ViewData [ list]作为SelectList)
如何从视图中获取下拉列表的选定值并将其传递给控制器?
我尝试了以下但是没有用。
string sTest = Request.Form [ list]。ToString();
我尝试过:
string sTest = Request.Form [ list]。ToString();
Dear All,
How can I Pass the Value from the View to Controller i.e.
I have a static Dropdown which I have created as follows.
1) Controller Code
var list = new SelectList(new[] { new { ID = "1", Name = "name1" }, new { ID = "2", Name = "name2" }, new { ID = "3", Name = "name3" }, }, "ID", "Name", 1); ViewData["list"] = list;
2) In My View I am binding the Dropdown as follows:
@Html.DropDownList("list", ViewData["list"] as SelectList)
how can I get the selected value of the dropdown from view and pass it to a controller?
I tried the following but it did not work.
string sTest = Request.Form["list"].ToString();
What I have tried:
string sTest = Request.Form["list"].ToString();
这篇关于如何将选定的下拉值从视图传递到控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!