【发布时间】:2014-01-17 07:03:16
【问题描述】:
我想知道我是否可以这样做,以及如何..
我有一个这样定义的动作结果:
public virtual JsonResult Created(string tableName, object where)
{
....some code
}
我正在使用 T4MVC 并尝试像这样调用操作结果:
MVC.MyController.Created("MyTable", new { Name = "Matt", Age = 11})
但是在控制器中 where 参数的类型是对象 {string[]} 它只有一个条目,看起来像这样:
where[0]="{ Name = "Matt", Age = 11 }"
有没有办法在 MyController 中将 where 参数作为匿名类型获取?
更新:
每隔几秒调用一次 Created 方法来查看数据库,如果创建了某行则返回 true。这是调用 Created 方法的方法:
public virtual ActionResult WaitingForUpdate(JsonResult pollAction, string redirectToOnSave = null)
{
return View("CommandSentPartial", new CommandSentModel
{
Message = "Waiting for update",
PollAction = pollAction,
RedirectTo = redirectToOnSave
});
}
然后我打电话
WaitingForUpdate(MVC.MyController.Created("MyTable", new { Name = "Matt", Age = 11}))
【问题讨论】:
-
T4MVC 不谈,你会如何在纯 MVC 中做到这一点?请参阅第 1.1 节。在t4mvc.codeplex.com/documentation
-
感谢您的建议!我尝试这样做: new MyController().Created("MyTable", new { Name = "Matt", Age = 11}) 并且工作得很好, where 参数是控制器中的匿名类型,所以我认为是 T4MVC 问题...
-
您尝试的是不同的,因为您正在进行直接的方法调用。使用 T4MVC 和直接 MVC,您最终会创建一个链接(一个 URL),单击该链接会调用您的操作。你能多展示一点你的代码吗?您如何使用方法调用返回的内容?例如你打电话给
Html.ActionLink()? -
每隔几秒调用一次 Created 方法来查看数据库,如果创建了某行则返回 true。
标签: asp.net-mvc-3 t4mvc