MVC 4动态动作方法的参数 [英] MVC 4 Dynamic action method argument

查看:89
本文介绍了MVC 4动态动作方法的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的类定义:

public class CallGroupViewModel
    {
        public string Name { get; set; }
        public string BulkEmails { get; set; }
        public List<dynamic> Members {get;set;}

    }

成员属性是一些动态淘汰赛code和内容的变化取决于UI的东西。我想走捷径,因为用户界面是如此在空中现在。

The Members property is some dynamic knockout code and the contents change depending on UI stuff. I am wanting to take a short cut since the UI is so up in the air right now.

我的问题是,当它到达我的操作方法,一切都被填充,其中包括会员但其对象的数组,我不能在个人财产得到在他们身上。

My problem is that when it get to my action method, everything gets populate, including Members but its a array of objects and I can't get at the individual properties on them.

public ActionResult SaveGroup(CallGroupViewModel group)

group.Members //this has a count
group.Members[0].email //this pukes as 'email' is not valid for 'object'

我可能只是失去了一些东西,任何帮助是AP preciated。

I'm probably just missing something, any help is appreciated.

谢谢!

推荐答案

其中填充MVC的操作方法参数的模型绑定系统不打算与动态对象的工作。系统要求输入信息,以了解绑定哪些信息。考虑更改模型使用强类型来代替。

The model binding system which populates MVC action method arguments isn't intended to work with dynamic objects. The system requires type information to know which information to bind. Consider changing your model to use strong types instead.

这篇关于MVC 4动态动作方法的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆