命名空間MvcApplication1.Models { 公共類GroupRepository { EgovtDataContext分貝=新EgovtDataContext();
public IQueryable<Group> FindAllGroups()
{
return db.Groups;
}
public IQueryable<Group> FindGroups()
{
return from Group in FindAllGroups()
orderby Group
select Group;
}
public Group GetGroups(int id)
{
return db.Groups.SingleOrDefault(d => d.int_GroupId == id);
}
//
public void Add(Group group)
{
db.Groups.InsertOnSubmit(group);
}
public void Delete(Group group)
{
db.Groups.DeleteOnSubmit(group);
}
//
// Persistence
public void Save()
{
db.SubmitChanges();
}
}
}
控制器
public ActionResult Index()
{
GroupRepository grouprepository = new GroupRepository();
ViewData["Group"] = grouprepository.FindGroups();
return View();
}
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage" %>
<% foreach (Group i in ViewData["Group"] as List<Group>)
{ %>
<input type="checkbox" name="Inhoud"
value="<%= i.int_GroupId %>" checked="checked" />
<% } %>
的事情是,它是不是能夠找到組ID,並顯示以下錯誤。解決辦法是什麼?
CS1061: 'System.Text.RegularExpressions.Group' does not contain a definition for 'int_GroupId' and no extension method 'int_GroupId' accepting a first argument of type 'System.Text.RegularExpressions.Group' could be found (are you missing a using directive or an assembly reference?)
FindGroups()返回什麼?是否有一些HTML缺失? – hunter 2010-05-07 19:19:18
public IQueryable FindGroups() { 從組中返回FindAllGroups() orderby組 select Group; } –
maztt
2010-05-07 19:21:42
什麼是Group的命名空間?我猜它不是'System.Text.RegularExpressions.Group' – hunter 2010-05-07 19:22:24