【发布时间】:2015-05-06 09:44:50
【问题描述】:
我正在尝试在 lambda 表达式中调用控制器操作方法,如下所示。
这里dtImporteddata是我的DataTable
public class DepartmentController : Controller
{
public ActionResult Create(FormCollection collection, int ParentDepartmentID)
{
return view();
}
}
dtImporteddata.Rows.Cast<DataRow>().Select(r => new DepartmentController().Create(new FormCollection{
{"ParentDepartmentID","57"},
{"DepartmentPrefix",r["Prefix"].ToString()},
{"DepartmentID","0"},
{"IsSpecialDepartment",null},
{"Description",r["Description"].ToString()},
{"Name",r["Name"].ToString()},
{"LocationIDs.$.PackedValue","4;;;"}
}, 0)).ToList();
如果我像上面这样写,Create() 方法会被完美调用,但如果我删除ToList(),那么Create() 不会被调用。
【问题讨论】:
-
@PatrickHofman Create 是我在控制器中的 Action 方法
-
@PatrickHofman 请查看已编辑的问题
标签: c# asp.net-mvc lambda