如何在url.action中将列表作为参数传递? [英] How to Pass list as parameter in url.action?
本文介绍了如何在url.action中将列表作为参数传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我如何使用url.action将视图中的整数值列表传递给mvc控制器?
can anyone help me how to pass list of integer values from view to mvc controller using url.action ??
推荐答案
public ActionResult Index(string[] data)
{
return View();
}
@{
var qs = HttpUtility.ParseQueryString("");
new List<string>{"one", "two", "three"}.ForEach(s => qs.Add("data", s));
}
<a href="@Url.Action("Index", "Home")?@qs">click</a>
更新:
Update:
@{
ViewBag.name = "xyz";
ViewBag.data = new List<string>{"one", "two", "three"};
var q = HttpUtility.ParseQueryString("");
q.Add("name", ViewBag.name);
foreach (var item in ViewBag.data)
{
q.Add("data", item.ToString());
}
}
<a href="@Url.Action("Index", "Home")?@q">click</a>
您可以在下面查看链接
http ://stackoverflow.com/questions/21785424/how-can-i-use-url-action-with-list-parameters [ ^ ]
You can check below link
http://stackoverflow.com/questions/21785424/how-can-i-use-url-action-with-list-parameters[^]
你c使用
You can use
@Url.Action("Index", "home", new { data1 = 0, data2 = 0 })
public ActionResult Index(int data1, int data2)
{
return View();
}
或
or
@Url.Action("Index", "home", new { data = yourintlist })
public ActionResult Index(int[] data)
{
return View();
}
这篇关于如何在url.action中将列表作为参数传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文