Bug with tuple and Typed views?
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?
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.
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 %>
精彩评论