有没有办法将IEnumerable参数传递给另一种方法 [英] Is there a way to pass an IEnumerable parameter to another method
本文介绍了有没有办法将IEnumerable参数传递给另一种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将IEnumerable模型参数从一种方法传递给另一种方法,但是当我调试代码时,即使方法签名相同,也不会传递该参数.
I am trying to pass a IEnumerable model parameter from one method to another however when I debug the code the parameter is not being passed even though the method signature is the same.
我尝试了有无前缀前缀
方法1:
[HttpPost]
public ActionResult Create_Filter([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<CourseFilterViewModel> courseFilterVM)
{
return RedirectToAction("Course", "Filter", courseFilterVM);
}
方法2:
public ActionResult Course([Bind(Prefix = "models")]IEnumerable<CourseFilterViewModel> courseFilterVM)
{
return View(courseFilterVM);
}
我希望整个模型都可以通过,但是我得到的是空值.
I am expecting the entire model to be passed but instead I am getting a null value.
推荐答案
您可以简单地执行以下操作:
You can simply do as follows:
[HttpPost]
public ActionResult Create_Filter([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<CourseFilterViewModel> courseFilterVM)
{
// Others stuffs here
return Course(courseFilterVM);
}
这篇关于有没有办法将IEnumerable参数传递给另一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文