[英]Passing value from QueryString into Index action of controller in asp.net mvc
我有这样的查询字符串:
http://localhost:2563/Skill?Months=1,2,3,4,5,6,7,8,9,10,11,12&SelectedMonth=8&Year=2016,2017,2018&SelectedYear=2016&....
我想将Months,SelectedMonth,Year和SelectedYear值传递到控制器的Index()中(Index是一个函数,接受0参数)。 另一个问题是,在Index函数完成之后,我希望运行绑定函数(在javascript中),以便按querystring中的SelectedMonth,SelectedYear将值绑定到dropdownlist中
请帮忙。 此功能有助于通过QueryString访问视图(而不是通过我的网站)非常感谢。
首先,动作名称错误。 您应该使用以下内容,
代替
其次,您需要传递一些参数。 方法如下:
public ActionResult Index(List<int> Months,int SelectedMonth,List<int> Year, int Year)
{
}
记住在您希望与它们一起使用时传递值。 如果不这样做,您将面临一些错误。 使用try catch块来防止和处理异常。
您可能还会在访问网页时遇到异常。 尝试放置可选参数,而不使用上面的参数。
public ActionResult Index(List<int>? Months,int? SelectedMonth,List<int>? Year, int? Year)
{
}
public ActionResult Index(List<int> Months,int SelectedMonth,List<int> Year, int Year)
{
}
或使用Reqest.QueryString
public ActionResult Index()
{
var months=Reqest.QueryString["Months"];
.
.
.
}
您需要从这里获取参数HttpContext.Current.Request.QueryString
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.