1

我的班级显示编译错误:

namespace Zone.Models
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Web;
    using System.Web.Mvc;
    using Zone.Models;


    public class MyViewModel
    {
       public MyInfo Info { get; set; }
       public PageNumberResults { get; set; }

    }
}

得到的错误如下:

Error 1 Invalid token '{' in class, struct, or interface member declaration 
Error 2 Invalid token ';' in class, struct, or interface member declaration
Error 3 Invalid token ';' in class, struct, or interface member declaration 
Error 4 Type or namespace definition, or end-of-file expected

我的控制器显示了游戏是如何通过界面输入到数据库中的:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using PagedList;
using System.Web.Mvc;
using Zone.Models;

namespace Zone.Controllers
{ 
    public class GameController : Controller
    {
        private mydbEntities db = new mydbEntities();



        public ViewResult Index(string Ordering, int? CounterForPage)
        {

            var FullDatabaseItem = from b in db.tblGames
                                   select b;

            var Info = db.tblGames.Include(x => x.tblConsole).Where(UserInfo => UserInfo.UserName.Equals(User.Identity.Name)).ToList();

            switch (Ordering)
            {
                case "HeadlineName":
                    FullDatabaseItem = FullDatabaseItem.OrderBy(b => b.GameName);
                    break;
                case "DatePosted":
                    FullDatabaseItem = FullDatabaseItem.OrderBy(b => b.ReleaseYear);
                    break;
                case "DiscriptionDate":
                    FullDatabaseItem = FullDatabaseItem.OrderBy(b => b.ReleaseYear);
                    break;
                default:
                    FullDatabaseItem = FullDatabaseItem.OrderByDescending(b => b.ReleaseYear);
                    break;
            }

            int pageSize = 3;
            int pageNumber = (CounterForPage ?? 1);
            var PageNumberResults = FullDatabaseItem.ToPagedList(pageNumber, pageSize);

            if (PageNumberResults.Any())
            {

                return View(new MyViewModel()
                {
                    Info = info,
                    PageNumberResults = FullDatabaseItem.Count()
                });
            }

            return View("ErrorView");
        }
    }
}

任何帮助,将不胜感激

4

4 回答 4

6

您缺少第二个属性中的类型:

   public ??? PageNumberResults { get; set; } 

而且您不需要using Zone.Models;声明,因为您的类位于该名称空间中。

于 2012-04-10T01:11:33.300 回答
1

我认为这条线给你错误

public PageNumberResults { get; set; }

你需要这种格式

可见性修饰符类型名称

前任 :public string Name { set;get;}

于 2012-04-10T01:12:26.033 回答
0

using Zone.Models;从您的代码中删除。通过声明,您已经在该名称空间中。

于 2012-04-10T01:09:21.923 回答
0

除了其他人引用的内容之外,不确定您是否只是没有完全复制控制器,但是您缺少}对类和命名空间的关闭。

于 2012-04-10T01:41:22.990 回答