元组和类型视图的错误?

时间:2010-09-02 10:23:16

标签: c# asp.net asp.net-mvc

如果我使用

定义视图,则会出现问题
Inherits="System.Web.Mvc.ViewPage<List<Tuple<string, DateTime?, double?, double?, double?>>>"

我得到了错误的错误:

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 {

但如果我删除最后一个“,双倍?”它会完美运作。 asp.net comiller中的一个错误?

3 个答案:

答案 0 :(得分:3)

是的,ASP.NET编译器生成的代码在您的示例中被破坏了。我可以重新创建它(Visual Studio 2010,.NET 4,ASP.NET MVC 2)并得到:

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

应该是:

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;
    ...

显然,abuse可以承担的数量有限。

答案 1 :(得分:2)

虽然我不知道为什么你的代码没有编译(看起来是正确的)而不是使用Tuple我会强烈建议你使用视图模型(甚至可能是编译器)对丑陋的窒息: - )):

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

有:

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

更具可读性

<%: Model.Item1 %>
<%: Model.Item2 %>

答案 2 :(得分:1)

我在6个月前遇到了同样的错误,使用自定义类作为视图模型对我来说是不可接受的,太多的类,我的所有模型都是动态的:),我仍然认为元组非常适合视图模型 Asp.net mvc 2 .net 4.0 error when View model type is Tuple with more than 4 items