动作控制器是否可以接受文字对象。例如,我有几个视图,我想在其中发布各种模型到单个控制器,然后可以确定传入模型对象以进行进一步处理。
模型样本:
public class Model1
{
// properties, etc.
}
public class Model2
{
// properties, etc.
}
public class Model3
{
// properties, etc.
}
控制器示例:
[HttpPost]
public ActionResult ProcessModel(Object anyModel)
{
// determine the model
if((anyModel as Model1) != null)
{
var model1 = anyModel as Model1;
// continue with code
}
else if((anyModel as Model2) != null)
{
var model2 = anyModel as Model2;
// continue with code
}
// continue with model check, etc.
}
我试过了,但我的控制器似乎没有拾取模型,因为我的对象参数仍然是空的。这可能吗?