views:

52

answers:

3

Got a werid problem with a view, if i define it with

Inherits="System.Web.Mvc.ViewPage<List<Tuple<string, DateTime?, double?, double?, double?>>>"

i get the werid error:

CS1003: Syntax error, '>' expected
Line 118:    public class views_report_intrestcalc_aspx : System.Web.Mvc.ViewPage<List<Tuple<string, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {

But it workes perfectly if i remove the last ", double?". A bug in the asp.net comiller?

+2  A: 

While I have no idea why your code doesn't compile (it looks right) instead of using a Tuple I would strongly recommend you using a view model (probably even the compiler chokes on the ugliness :-)):

Inherits="System.Web.Mvc.ViewPage<List<MyViewModel>>"

Having:

<%: Model.Username %>
<%: Model.Date %>

is far more readable than:

<%: Model.Item1 %>
<%: Model.Item2 %>
Darin Dimitrov
+2  A: 

Yes, the code the ASP.NET compiler generates is broken for your example. I can re-create this (Visual Studio 2010, .NET 4, ASP.NET MVC 2) and get:

public class views_home_index_aspx : System.Web.Mvc.ViewPage<List<Tuple<string,
        System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {
    private static bool @__initialized;
    ...

When it should be:

public class views_home_index_aspx : System.Web.Mvc.ViewPage<List<Tuple<string,
        DateTime?, double?, double?, double?>>>, 
        System.Web.SessionState.IRequiresSessionState,
        System.Web.IHttpHandler {
    private static bool @__initialized;
    ...

Apparently, there's a limit to the amount of abuse it can take.

bzlm
A: 

i had the same error 6 months ago, using custom class as view model is not acceptable for me, too much classes, all my models are dynamic :), i still think that tuple is great for view model http://stackoverflow.com/questions/2695134/asp-net-mvc-2-net-4-0-error-when-view-model-type-is-tuple-with-more-than-4-items

Bojan