Asp.net mvc 查询字符串下拉菜单mvc asp.net选定项列表
如果条件=2,我想写查询字符串 我有下拉菜单在这个菜单中,我有位置是{主,左,上,下} 如果我在本地主机中写入localhost:27593管理项create?type=2 应该在我看到的位置上吗 在asp.net和mvc中,我想写正确的代码,请帮助我Asp.net mvc 查询字符串下拉菜单mvc asp.net选定项列表,asp.net-mvc,selected,Asp.net Mvc,Selected,如果条件=2,我想写查询字符串 我有下拉菜单在这个菜单中,我有位置是{主,左,上,下} 如果我在本地主机中写入localhost:27593管理项create?type=2 应该在我看到的位置上吗 在asp.net和mvc中,我想写正确的代码,请帮助我 public ActionResult Create (int? id) { //querystring // 2 ise int TYPEE = HttpUtility.UrlDecod
public ActionResult Create (int? id)
{
//querystring
// 2 ise
int TYPEE = HttpUtility.UrlDecode(Request.QueryString["typee"] );
string[] separateURL = url.Split('?');
NameValueCollection queryString =
System.Web.HttpUtility.ParseQueryString(separateURL[1]) ;
if (TYPEE == 2)
{
SelectListItem[] items = new SelectListItem[2];
items[0] = new SelectListItem"main" ,"1");
items[1] = new SelectListItem("left" , "2");
DropDownList1.Items.AddRange(items);
DropDownList1.DataBind();
}
else
{
SelectListItem[] items = new SelectListItem[5];
items[0] = new SelectListItem("main", "1");
items[1] = new SelectListItem("left", "2");
items[2] = new SelectListItem("right", "3");
items[3] = new SelectListItem("top", "4");
items[3] = new SelectListItem("bottom", "5");
DropDownList1.Items.AddRange(items);
DropDownList1.DataBind();
return View();
你为什么不直接用它呢
public ActionResult Create (int type, int? id)
这样,默认模型绑定器将把查询字符串中的type值绑定到变量类型
编辑:
我刚才也看到了一个输入错误,您正在QueryString集合中查找“type”键,但是其中没有这样的键,只有“type”键
int TYPEE = HttpUtility.UrlDecode(Request.QueryString["type"])