开发者

C# - Pass data back to view from ActionFilter via ViewData

I have created a little execution timer and as an extra id like to be able to have the option to display all timing results on the bottom of a view via the ViewData for live timers whilst developing (Opposed to placing all entries in a database to monitor performance) Basically the timer places all time splits into a list> and I am currently trying to pass this into ViewData but when its received the other end I seem unable to cast it back.

var Test = _timer.SplitList.Select(e => new { Id = e.Key, Value = e.Value }).OrderBy(e => e.Id).ToList().AsQueryable();
filterContext.Controller.ViewData["Timing"] = Test;

Once received by the view it seems to be received as List<AnonymoyusType<string, double>>.

How do I go about casting it back to something usable? Casting back to List<KeyValuePair<s开发者_如何转开发tring, double>> does not seem to work at all!

Any help would be really appreciated!


Anonymous types cannot easily be passed across methods.

You should create a list of Tuples/KeyValuePairs or write your own class.

Also, don't call AsQueryable().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜