开发者

MVC - usage of and anonymous types from LINQ queries, and third party controls

This is a conceptual question but I think it does have an 'answer', hopefully it won't be knocked on the head.

I develop in asp.net webforms (C#) using a lot of linq to sql (have used EF also but l2s is enough for most of my need开发者_如何学JAVAs). I just completed an initial MVC tutorial, along with the 'code first' entity models. I can see some benefits particularly around 'separation of concerns', but I'd like your views on whether this would be suitable for me given the type of things I develop. The questions:

a) The whole MVC paradigm seems to assume defined 'classes' (eg the 'movie' class in the MVC tute I did). Must of what I do involves creating adhoc anonymous types from linq and binding them to grids or charts. To use MVC would I have to create defined classes every time in order to pass them from the controller to the view? This question (http://stackoverflow.com/questions/410073/linq-anonymous-types-mvc-views-help) seems to suggest it, or a dictionary as a workaround which would only work in limited cases.

b) I use quite a few third party controls (telerik, devexpress and so on). It seems none of those would work with MVC? Telerik have some free MVC extensions, but I'm figuring my investment in those other controlsets would be lost?

Sorry for the noobish questions :)

Mark


a) Aside from this unusual trick, http://tomasp.net/blog/cannot-return-anonymous-type-from-method.aspx, anonymous types are for processing within a method, not intended for passing between contexts. The controller context and the view context are different; you should use a typed object to pass data between them. That's exactly what ViewModel objects should be used for so don't resist their usage.

b) It is true, your webforms controls will not benefit you in MVC, but you'll also find that the popular component shops have long ago brought MVC extension libraries to market as much as they can in anticipation of the move from webforms to MVC. Telerik is among them - http://www.telerik.com/products/aspnet-mvc.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜