我有一个像这样的查询字符串:
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 值传递到 Controller 的 Index() 中(Index 是一个带有 0 个参数的函数)。 另一个问题是,索引函数完成后,我希望运行绑定(bind)函数(在 javascript 中),通过查询字符串中的 SelectedMonth、SelectedYear 将值绑定(bind)到下拉列表
请帮忙。此功能有助于通过 QueryString 访问 View (而不是通过我的网站) 非常感谢。
最佳答案
首先, Action 名称错误。您应该使用以下内容,
而不是
第二, 您需要传递一些参数。 方法如下:
public ActionResult Index(List<int> Months,int SelectedMonth,List<int> Year, int Year)
{
}
请记住传递您希望使用的值。如果不这样做,您将面临一些错误。使用try catch block 来防止和处理异常。
您还可能在访问网页时遇到异常。尝试添加可选参数而不是使用上面的参数。
public ActionResult Index(List<int>? Months,int? SelectedMonth,List<int>? Year, int? Year)
{
}
关于javascript - 将值从 QueryString 传递到 asp.net mvc 中 Controller 的 Index 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38974358/