开发者

if all my views are passed a strongly typed viewdata, if they have a baseviewdata class, can I set a property in onexecuting?

I want all my views to inherit from a baseview data so I can set some shared pro开发者_JS百科perties that all my views will need.

Can I set some properties in OnExecuting so I don't have to do it for all Actions?

I want to then display the string value of the property in all my view pages.

If yes, how can I do this? I need to hook into the base view data somehow?

so i'll have:

public MyViewData : ViewData { }

And I need one for generics also?


The simplest answer is to make a generic helper method that instantiates the ViewData classes and sets the properties.
You can then call this method in your actions to create the ViewData instances.

For example:

static TData CreateData<TData>() where TData : BaseViewData, new() {
    TData retVal = new TData();
    //Set properties...
    return retVal;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜