Problem with CheckBoxes ASP.NET MVC

Repository

namespace MvcApplication1.Models {public class GroupRepository {EgovtDataContext db = new 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();
    } 

}

}

CONTROLLER

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" />

<% } %>  

The fact is that he cannot find the group identifier and display the following error. What is the solution?

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?)
+3
source share
4 answers

, FindGroups() :

<% foreach (var i in ViewData["Group"] as List<MyNamespace.Blah.Group>)
   { %>
       <input type="checkbox" name="Inhoud" 
              value="<%= i.int_GroupId %>" checked="checked" />
<% } %>  

Web.Config . , `System.Text.RegularExpressions '.

MVC LINQ

(ViewData["Group"] as List<MyNamespace.Blah.Group>)
    .ForEach(g => Response.Write(
        Html.CheckBox("Inhoud", true, new { value = g.int_GroupId })));
+3

-/ web.config.

  <pages>
    <namespaces>
        ...
        <add namespace="Com.Example.Foo.Interfaces" />
        <add namespace="Com.Example.Foo.Common" />
        ...
    </namespaces>
  </pages

, , ViewData , .

using Com.Example.Foo.Interfaces;
using Com.Example.Foo.Common;

public class GroupModel
{
     public IEnumerable<Group> Groups { get; set; }
}

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
    Inherits="System.Web.Mvc.ViewPage<GroupModel>" %> 

<% foreach (var i in Model.Groups) 
   { %> 
       <input type="checkbox" name="Inhoud"  
              value="<%= i.int_GroupId %>" checked="checked" /> 
<% } %>  
+2

, , aspx , System.Text.RegularExpressions.Group, , ActionResult, Group, , Group, , System.Text.RegularExpressions, , Group

+1

, , , namespace issue. Group System.Text.RegularExpressions.Group, , , Group. forloop, , System.Text.RegularExpressions.Group namespace.

+1
source

Source: https://habr.com/ru/post/1744552/


All Articles