我的班级显示编译错误:
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");
}
}
}
任何帮助将不胜感激
答案 0 :(得分:6)
你错过了第二个属性中的类型:
public ??? PageNumberResults { get; set; }
并且您不需要using Zone.Models;
声明,因为您的类位于该命名空间中。
答案 1 :(得分:1)
我认为这一行给你的错误
public PageNumberResults { get; set; }
您需要这种格式
visibilitymodifier类型名称
例如:public string Name { set;get;}
答案 2 :(得分:0)
从代码中删除using Zone.Models;
。您已通过声明进入该命名空间。
答案 3 :(得分:0)
除了别人引用的内容之外,不确定你是不是完全没有复制你的控制器,但是你错过了关于类和名称空间的结束}
。