类型的对象.NET MVC Action参数 [英] .NET MVC Action parameter of type object
问题描述
如果我有一个简单的控制器路由如下:
If I have a simple controller routed as follows:
context.MapRoute(
"Default",
"{controller}/{action}",
new { controller = "Base", action = "Foo"}
);
和控制器的Foo操作如下:
And the controller Foo action is as follows:
[HttpPost]
public ActionResult Foo(object bar) { ... }
如何栏
的约束?我已经调试,并看到它是一个字符串
,但我不知道这是否会永远被编组为一个字符串。
How will bar
be bound? I have debugged and see it is a string
, but I'm not sure if it will always be marshalled to a string.
基本上我想有办法接受布尔
,列表< INT>
和 INT
。我最多可以发送一个类型参数,并做模型从岗位结合自己。 (该文章是一个表单POST)。
Basically I want to have the method accept a bool
, List<int>
, and int
. I can send up a type parameter and do the model binding myself from the post. (The post is a form post).
下面是我目前的职位&安培;巴=假
或&安培;巴= 23
或&放大器;酒吧[0] = 24&安培;酒吧[1] = 22
Here are my current posts &bar=False
or &bar=23
or &bar[0]=24&bar[1]=22
.
我知道我可以看看富action方法里面的职位,但我想在最好的办法某些输入来处理这MVC3
I know I can look at the post inside the Foo action method, but I want some input on the best way to handle this in MVC3
推荐答案
在这种情况下,我可能会创建一个自定义ModelBinder的:
In this case I would probably create a custom ModelBinder:
的http://buildstarted.com/2010/09/12/custom-model-binders-in-mvc-3-with-imodelbinder/
那么也许使用动态对象,允许多种类型。看到这里
then maybe use a dynamic object to allow for multiple types. See here
MVC3 ModelBinder的为DynamicObject
这篇关于类型的对象.NET MVC Action参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!