开发者

Does Spark view engine support anonymous types as viewdata

I'm setting an anonymous type like this:

PropertyBag["model"] = new 
                                {
                                    IsHome = areaId == "Home",
                                    IsGroups 开发者_高级运维= areaId == "Groups",
                                    IsUsers = areaId == "Users",
                                    IsComputers = areaId == "Computers",
                                };

And in my view I want to be able to call model.IsHome from inside a condition attribute output like this:

<a href="/Home" class="dropdown selected?{model.IsHome}">Home</a>

But this doesn't seem to work with anonymous types!

I've tried to set my viewdata to object:

<viewdata model="object" />

Any ideas if this is supported at all?


There's an example of doing something similar to what you're trying here: Late-bound Eval – email templates revisited. Although it's related to using Spark for email templates, you should be able to do the same in your views. It may or may not have an effect on performance though, may want to profile it before and after to make sure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜