My view don´t display my tabledata in mvc












0















Have a small problem, probably an easy solution but cant figure it out!



I have problem to display my data in my view. I have 5 checkboxes that i want to display all data that belongs to each checkbox. The checkbox work when i hardcode my data in a list in my view, but it doesent work when i want to display the data from my table, what are i am missing?



My code



My model (created from my table with entity framework)



 public partial class Full
{
public int Id { get; set; }
public string Channel { get; set; }
public string Program { get; set; }
public string Category { get; set; }
public string Date { get; set; }
public string Time { get; set; }
public string Length { get; set; }
}


My view



@model IEnumerable<Uppgift4.Models.Full>

@{
ViewBag.Title = "channel_Index";
var list = Model.ToList();
var list1 = list.Where(_ => _.Channel == "SVT1").Select(_ =>
_.Program).ToList();//select records which in one channel
var list2 = list.Where(_ => _.Channel == "SVT2").Select(_ =>
_.Program).ToList();
var list3 = list.Where(_ => _.Channel == "TV3").Select(_ =>
_.Program).ToList();
var list4 = list.Where(_ => _.Channel == "TV4").Select(_ =>
_.Program).ToList();
var list5 = list.Where(_ => _.Channel == "Kanal5").Select(_ =>
_.Program).ToList();

}
<style>
.hiddenRow {
padding: 0 !important;
}

.in-line {
display: inline;
}
</style>
<br />
<table class="table table-condensed" style="border-collapse:collapse;">
<thead>
<tr>
<th>
Channel
</th>
<th>

</th>
</tr>
</thead>
<tbody>
<tr class="accordion-toggle">
<td><input type="checkbox" data-toggle="collapse" data-target="div
[id*='demo1']" /> SVT1</td>
</tr>
@for (var i = 0; i < @list1.Count; i++)
{
<tr><td colspan="2" class="hiddenRow"><div id="demo1+'@i'+"
class="accordian-body collapse">Program:@list1[i]</div> </td> </tr>

}
<tr data-toggle="collapse" data-target="#demo2" class="accordion-toggle">
<td><input type="checkbox" data-toggle="collapse" data-target="div
[id*='demo2']" /> SVT2</td>
</tr>
@for (var i = 0; i < @list2.Count; i++)
{
<tr><td colspan="2" class="hiddenRow"><div id="demo2+'@i'+"
class="accordian-body collapse">Program:@list2[i]</div> </td> </tr>

}

<tr data-toggle="collapse" data-target="#demo3" class="accordion-toggle">
<td><input type="checkbox" data-toggle="collapse" data-target="div
[id*='demo3']" /> TV3</td>
</tr>
@for (var i = 0; i < @list3.Count; i++)
{
<tr><td colspan="2" class="hiddenRow"><div id="demo3+'@i'+"
class="accordian-body collapse">Program:@list3[i]</div> </td> </tr>

}

<tr data-toggle="collapse" data-target="#demo4" class="accordion-toggle">
<td><input type="checkbox" data-toggle="collapse" data-target="div
[id*='demo4']" /> TV4</td>
</tr>
@for (var i = 0; i < @list4.Count; i++)
{
<tr><td colspan="2" class="hiddenRow"><div id="demo4+'@i'+"
class="accordian-body collapse">Program:@list4[i]</div> </td> </tr>

}

<tr data-toggle="collapse" data-target="#demo5" class="accordion-toggle">
<td><input type="checkbox" data-toggle="collapse" data-target="div
[id*='demo5']" /> Kanal5</td>
</tr>
@for (var i = 0; i < @list5.Count; i++)
{
<tr><td colspan="2" class="hiddenRow"><div id="demo5+'@i'+"
class="accordian-body collapse">Program:@list5[i]</div> </td> </tr>

}
</tbody>
</table>


My controller



public class FavoritChannelsController : Controller
{
TvProgramDBEntities db = new TvProgramDBEntities();
Full f = new Full();

public ActionResult channel_index()
{
List<Full> model = new List<Full>();
{
model.Add(new Full { Channel = "SVT1", Program = "fame" });
model.Add(new Full { Channel = "SVT1", Program = "sport" });
model.Add(new Full { Channel = "SVT2", Program = "news" });
model.Add(new Full { Channel = "TV3", Program = "hockey" });
return View(model);

}
}


so this actionresult work when i harcode my list, and now when i run the program and push the checkbox SVT1 i get two programs Fame and sport.



But i want to present all the data i have in my table, so i try this:



 public ActionResult channel_index()
{
List<Full> model = new List<Full>();
foreach (var item in db.Full)
{
f.Channel = item.Channel;
f.Program = item.Program;
model.Add(f);
}
return View(model);
}


but i dont get any data in my view when i run the program..



Anybody know a solution?










share|improve this question



























    0















    Have a small problem, probably an easy solution but cant figure it out!



    I have problem to display my data in my view. I have 5 checkboxes that i want to display all data that belongs to each checkbox. The checkbox work when i hardcode my data in a list in my view, but it doesent work when i want to display the data from my table, what are i am missing?



    My code



    My model (created from my table with entity framework)



     public partial class Full
    {
    public int Id { get; set; }
    public string Channel { get; set; }
    public string Program { get; set; }
    public string Category { get; set; }
    public string Date { get; set; }
    public string Time { get; set; }
    public string Length { get; set; }
    }


    My view



    @model IEnumerable<Uppgift4.Models.Full>

    @{
    ViewBag.Title = "channel_Index";
    var list = Model.ToList();
    var list1 = list.Where(_ => _.Channel == "SVT1").Select(_ =>
    _.Program).ToList();//select records which in one channel
    var list2 = list.Where(_ => _.Channel == "SVT2").Select(_ =>
    _.Program).ToList();
    var list3 = list.Where(_ => _.Channel == "TV3").Select(_ =>
    _.Program).ToList();
    var list4 = list.Where(_ => _.Channel == "TV4").Select(_ =>
    _.Program).ToList();
    var list5 = list.Where(_ => _.Channel == "Kanal5").Select(_ =>
    _.Program).ToList();

    }
    <style>
    .hiddenRow {
    padding: 0 !important;
    }

    .in-line {
    display: inline;
    }
    </style>
    <br />
    <table class="table table-condensed" style="border-collapse:collapse;">
    <thead>
    <tr>
    <th>
    Channel
    </th>
    <th>

    </th>
    </tr>
    </thead>
    <tbody>
    <tr class="accordion-toggle">
    <td><input type="checkbox" data-toggle="collapse" data-target="div
    [id*='demo1']" /> SVT1</td>
    </tr>
    @for (var i = 0; i < @list1.Count; i++)
    {
    <tr><td colspan="2" class="hiddenRow"><div id="demo1+'@i'+"
    class="accordian-body collapse">Program:@list1[i]</div> </td> </tr>

    }
    <tr data-toggle="collapse" data-target="#demo2" class="accordion-toggle">
    <td><input type="checkbox" data-toggle="collapse" data-target="div
    [id*='demo2']" /> SVT2</td>
    </tr>
    @for (var i = 0; i < @list2.Count; i++)
    {
    <tr><td colspan="2" class="hiddenRow"><div id="demo2+'@i'+"
    class="accordian-body collapse">Program:@list2[i]</div> </td> </tr>

    }

    <tr data-toggle="collapse" data-target="#demo3" class="accordion-toggle">
    <td><input type="checkbox" data-toggle="collapse" data-target="div
    [id*='demo3']" /> TV3</td>
    </tr>
    @for (var i = 0; i < @list3.Count; i++)
    {
    <tr><td colspan="2" class="hiddenRow"><div id="demo3+'@i'+"
    class="accordian-body collapse">Program:@list3[i]</div> </td> </tr>

    }

    <tr data-toggle="collapse" data-target="#demo4" class="accordion-toggle">
    <td><input type="checkbox" data-toggle="collapse" data-target="div
    [id*='demo4']" /> TV4</td>
    </tr>
    @for (var i = 0; i < @list4.Count; i++)
    {
    <tr><td colspan="2" class="hiddenRow"><div id="demo4+'@i'+"
    class="accordian-body collapse">Program:@list4[i]</div> </td> </tr>

    }

    <tr data-toggle="collapse" data-target="#demo5" class="accordion-toggle">
    <td><input type="checkbox" data-toggle="collapse" data-target="div
    [id*='demo5']" /> Kanal5</td>
    </tr>
    @for (var i = 0; i < @list5.Count; i++)
    {
    <tr><td colspan="2" class="hiddenRow"><div id="demo5+'@i'+"
    class="accordian-body collapse">Program:@list5[i]</div> </td> </tr>

    }
    </tbody>
    </table>


    My controller



    public class FavoritChannelsController : Controller
    {
    TvProgramDBEntities db = new TvProgramDBEntities();
    Full f = new Full();

    public ActionResult channel_index()
    {
    List<Full> model = new List<Full>();
    {
    model.Add(new Full { Channel = "SVT1", Program = "fame" });
    model.Add(new Full { Channel = "SVT1", Program = "sport" });
    model.Add(new Full { Channel = "SVT2", Program = "news" });
    model.Add(new Full { Channel = "TV3", Program = "hockey" });
    return View(model);

    }
    }


    so this actionresult work when i harcode my list, and now when i run the program and push the checkbox SVT1 i get two programs Fame and sport.



    But i want to present all the data i have in my table, so i try this:



     public ActionResult channel_index()
    {
    List<Full> model = new List<Full>();
    foreach (var item in db.Full)
    {
    f.Channel = item.Channel;
    f.Program = item.Program;
    model.Add(f);
    }
    return View(model);
    }


    but i dont get any data in my view when i run the program..



    Anybody know a solution?










    share|improve this question

























      0












      0








      0








      Have a small problem, probably an easy solution but cant figure it out!



      I have problem to display my data in my view. I have 5 checkboxes that i want to display all data that belongs to each checkbox. The checkbox work when i hardcode my data in a list in my view, but it doesent work when i want to display the data from my table, what are i am missing?



      My code



      My model (created from my table with entity framework)



       public partial class Full
      {
      public int Id { get; set; }
      public string Channel { get; set; }
      public string Program { get; set; }
      public string Category { get; set; }
      public string Date { get; set; }
      public string Time { get; set; }
      public string Length { get; set; }
      }


      My view



      @model IEnumerable<Uppgift4.Models.Full>

      @{
      ViewBag.Title = "channel_Index";
      var list = Model.ToList();
      var list1 = list.Where(_ => _.Channel == "SVT1").Select(_ =>
      _.Program).ToList();//select records which in one channel
      var list2 = list.Where(_ => _.Channel == "SVT2").Select(_ =>
      _.Program).ToList();
      var list3 = list.Where(_ => _.Channel == "TV3").Select(_ =>
      _.Program).ToList();
      var list4 = list.Where(_ => _.Channel == "TV4").Select(_ =>
      _.Program).ToList();
      var list5 = list.Where(_ => _.Channel == "Kanal5").Select(_ =>
      _.Program).ToList();

      }
      <style>
      .hiddenRow {
      padding: 0 !important;
      }

      .in-line {
      display: inline;
      }
      </style>
      <br />
      <table class="table table-condensed" style="border-collapse:collapse;">
      <thead>
      <tr>
      <th>
      Channel
      </th>
      <th>

      </th>
      </tr>
      </thead>
      <tbody>
      <tr class="accordion-toggle">
      <td><input type="checkbox" data-toggle="collapse" data-target="div
      [id*='demo1']" /> SVT1</td>
      </tr>
      @for (var i = 0; i < @list1.Count; i++)
      {
      <tr><td colspan="2" class="hiddenRow"><div id="demo1+'@i'+"
      class="accordian-body collapse">Program:@list1[i]</div> </td> </tr>

      }
      <tr data-toggle="collapse" data-target="#demo2" class="accordion-toggle">
      <td><input type="checkbox" data-toggle="collapse" data-target="div
      [id*='demo2']" /> SVT2</td>
      </tr>
      @for (var i = 0; i < @list2.Count; i++)
      {
      <tr><td colspan="2" class="hiddenRow"><div id="demo2+'@i'+"
      class="accordian-body collapse">Program:@list2[i]</div> </td> </tr>

      }

      <tr data-toggle="collapse" data-target="#demo3" class="accordion-toggle">
      <td><input type="checkbox" data-toggle="collapse" data-target="div
      [id*='demo3']" /> TV3</td>
      </tr>
      @for (var i = 0; i < @list3.Count; i++)
      {
      <tr><td colspan="2" class="hiddenRow"><div id="demo3+'@i'+"
      class="accordian-body collapse">Program:@list3[i]</div> </td> </tr>

      }

      <tr data-toggle="collapse" data-target="#demo4" class="accordion-toggle">
      <td><input type="checkbox" data-toggle="collapse" data-target="div
      [id*='demo4']" /> TV4</td>
      </tr>
      @for (var i = 0; i < @list4.Count; i++)
      {
      <tr><td colspan="2" class="hiddenRow"><div id="demo4+'@i'+"
      class="accordian-body collapse">Program:@list4[i]</div> </td> </tr>

      }

      <tr data-toggle="collapse" data-target="#demo5" class="accordion-toggle">
      <td><input type="checkbox" data-toggle="collapse" data-target="div
      [id*='demo5']" /> Kanal5</td>
      </tr>
      @for (var i = 0; i < @list5.Count; i++)
      {
      <tr><td colspan="2" class="hiddenRow"><div id="demo5+'@i'+"
      class="accordian-body collapse">Program:@list5[i]</div> </td> </tr>

      }
      </tbody>
      </table>


      My controller



      public class FavoritChannelsController : Controller
      {
      TvProgramDBEntities db = new TvProgramDBEntities();
      Full f = new Full();

      public ActionResult channel_index()
      {
      List<Full> model = new List<Full>();
      {
      model.Add(new Full { Channel = "SVT1", Program = "fame" });
      model.Add(new Full { Channel = "SVT1", Program = "sport" });
      model.Add(new Full { Channel = "SVT2", Program = "news" });
      model.Add(new Full { Channel = "TV3", Program = "hockey" });
      return View(model);

      }
      }


      so this actionresult work when i harcode my list, and now when i run the program and push the checkbox SVT1 i get two programs Fame and sport.



      But i want to present all the data i have in my table, so i try this:



       public ActionResult channel_index()
      {
      List<Full> model = new List<Full>();
      foreach (var item in db.Full)
      {
      f.Channel = item.Channel;
      f.Program = item.Program;
      model.Add(f);
      }
      return View(model);
      }


      but i dont get any data in my view when i run the program..



      Anybody know a solution?










      share|improve this question














      Have a small problem, probably an easy solution but cant figure it out!



      I have problem to display my data in my view. I have 5 checkboxes that i want to display all data that belongs to each checkbox. The checkbox work when i hardcode my data in a list in my view, but it doesent work when i want to display the data from my table, what are i am missing?



      My code



      My model (created from my table with entity framework)



       public partial class Full
      {
      public int Id { get; set; }
      public string Channel { get; set; }
      public string Program { get; set; }
      public string Category { get; set; }
      public string Date { get; set; }
      public string Time { get; set; }
      public string Length { get; set; }
      }


      My view



      @model IEnumerable<Uppgift4.Models.Full>

      @{
      ViewBag.Title = "channel_Index";
      var list = Model.ToList();
      var list1 = list.Where(_ => _.Channel == "SVT1").Select(_ =>
      _.Program).ToList();//select records which in one channel
      var list2 = list.Where(_ => _.Channel == "SVT2").Select(_ =>
      _.Program).ToList();
      var list3 = list.Where(_ => _.Channel == "TV3").Select(_ =>
      _.Program).ToList();
      var list4 = list.Where(_ => _.Channel == "TV4").Select(_ =>
      _.Program).ToList();
      var list5 = list.Where(_ => _.Channel == "Kanal5").Select(_ =>
      _.Program).ToList();

      }
      <style>
      .hiddenRow {
      padding: 0 !important;
      }

      .in-line {
      display: inline;
      }
      </style>
      <br />
      <table class="table table-condensed" style="border-collapse:collapse;">
      <thead>
      <tr>
      <th>
      Channel
      </th>
      <th>

      </th>
      </tr>
      </thead>
      <tbody>
      <tr class="accordion-toggle">
      <td><input type="checkbox" data-toggle="collapse" data-target="div
      [id*='demo1']" /> SVT1</td>
      </tr>
      @for (var i = 0; i < @list1.Count; i++)
      {
      <tr><td colspan="2" class="hiddenRow"><div id="demo1+'@i'+"
      class="accordian-body collapse">Program:@list1[i]</div> </td> </tr>

      }
      <tr data-toggle="collapse" data-target="#demo2" class="accordion-toggle">
      <td><input type="checkbox" data-toggle="collapse" data-target="div
      [id*='demo2']" /> SVT2</td>
      </tr>
      @for (var i = 0; i < @list2.Count; i++)
      {
      <tr><td colspan="2" class="hiddenRow"><div id="demo2+'@i'+"
      class="accordian-body collapse">Program:@list2[i]</div> </td> </tr>

      }

      <tr data-toggle="collapse" data-target="#demo3" class="accordion-toggle">
      <td><input type="checkbox" data-toggle="collapse" data-target="div
      [id*='demo3']" /> TV3</td>
      </tr>
      @for (var i = 0; i < @list3.Count; i++)
      {
      <tr><td colspan="2" class="hiddenRow"><div id="demo3+'@i'+"
      class="accordian-body collapse">Program:@list3[i]</div> </td> </tr>

      }

      <tr data-toggle="collapse" data-target="#demo4" class="accordion-toggle">
      <td><input type="checkbox" data-toggle="collapse" data-target="div
      [id*='demo4']" /> TV4</td>
      </tr>
      @for (var i = 0; i < @list4.Count; i++)
      {
      <tr><td colspan="2" class="hiddenRow"><div id="demo4+'@i'+"
      class="accordian-body collapse">Program:@list4[i]</div> </td> </tr>

      }

      <tr data-toggle="collapse" data-target="#demo5" class="accordion-toggle">
      <td><input type="checkbox" data-toggle="collapse" data-target="div
      [id*='demo5']" /> Kanal5</td>
      </tr>
      @for (var i = 0; i < @list5.Count; i++)
      {
      <tr><td colspan="2" class="hiddenRow"><div id="demo5+'@i'+"
      class="accordian-body collapse">Program:@list5[i]</div> </td> </tr>

      }
      </tbody>
      </table>


      My controller



      public class FavoritChannelsController : Controller
      {
      TvProgramDBEntities db = new TvProgramDBEntities();
      Full f = new Full();

      public ActionResult channel_index()
      {
      List<Full> model = new List<Full>();
      {
      model.Add(new Full { Channel = "SVT1", Program = "fame" });
      model.Add(new Full { Channel = "SVT1", Program = "sport" });
      model.Add(new Full { Channel = "SVT2", Program = "news" });
      model.Add(new Full { Channel = "TV3", Program = "hockey" });
      return View(model);

      }
      }


      so this actionresult work when i harcode my list, and now when i run the program and push the checkbox SVT1 i get two programs Fame and sport.



      But i want to present all the data i have in my table, so i try this:



       public ActionResult channel_index()
      {
      List<Full> model = new List<Full>();
      foreach (var item in db.Full)
      {
      f.Channel = item.Channel;
      f.Program = item.Program;
      model.Add(f);
      }
      return View(model);
      }


      but i dont get any data in my view when i run the program..



      Anybody know a solution?







      c# entity-framework model-view-controller






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 10:01









      MichaelMichael

      33




      33
























          6 Answers
          6






          active

          oldest

          votes


















          0














          The problem is if you write b.Full you will get IQueryable<Full> but if you want to do the query you should write .toList().



          Updated:



          In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "")



          You can see some another examples how to remove whitespacehttp://www.csharp411.com/remove-whitespace-from-c-strings/



          public ActionResult channel_index()
          {
          List<Full> model = new List<Full>();
          //you need to do the query with ToList
          var list = db.Full.ToList();

          foreach (var item in list )
          {
          var initedF = new Full({
          Channel = Regex.Replace(item.Channel, @"s", ""),
          Program = Regex.Replace(item.Program, @"s", "")
          });
          //f.Channel = item.Channel;
          //f.Program = item.Program;
          model.Add(initedF);
          }
          return View(model);
          }





          share|improve this answer


























          • @Michael please provide TvProgramDBEntities class code

            – Maksym Labutin
            Nov 23 '18 at 11:26











          • Not sure what you mean with Entity framework class, is it the table i posted you mean? Tryed your code but cant still get any data in my view #maksym

            – Michael
            Nov 23 '18 at 11:27











          • could you please share your code in the TvProgramDBEntities class?

            – Maksym Labutin
            Nov 23 '18 at 11:30













          • TvProgramDBEntitities is my databasconnection. My data is stored in table full (class). Cant find any special class code for TVProgramDBEntities, where do i find that in MVC Project? My database have no relationsship to other tables..

            – Michael
            Nov 23 '18 at 11:35













          • Ok. Then do this before foreach var list = db.Full; and send me what will be in the list

            – Maksym Labutin
            Nov 23 '18 at 11:40



















          0














          CREATE TABLE [dbo].[Full] (
          [Id] INT IDENTITY (1, 1) NOT NULL,
          [Channel] NCHAR (50) NULL,
          [Program] NCHAR (50) NULL,
          [Category] NCHAR (50) NULL,
          [Date] NCHAR (50) NULL,
          [Time] NCHAR (50) NULL,
          [Length] NCHAR (10) NULL,
          PRIMARY KEY CLUSTERED ([Id] ASC)
          );





          share|improve this answer































            0














            enter image description here



            printscreen of my full table. it have 180 rows and the program fron channel SVT2, TV3, TV4, Kanal5 come later on






            share|improve this answer
























            • Good. But what the request return? You can simply check it with var list = db.Full; before foreach loop and send me what will be in the list

              – Maksym Labutin
              Nov 23 '18 at 11:54











            • added som printscreen, hope it give some info ;-)

              – Michael
              Nov 23 '18 at 12:18



















            0














            enter image description here



            printscreen when i run the program..






            share|improve this answer
























            • Good. I edited my answer. You just need add .ToList() and all should work (var list = db.Full.ToList();). See my answer

              – Maksym Labutin
              Nov 23 '18 at 12:17



















            0














            enter image description here



            and the model when i run






            share|improve this answer
























            • I found the problem. Please read my answer again =)

              – Maksym Labutin
              Nov 23 '18 at 12:29








            • 1





              ahh, now i saw it, you mean: Updated: In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "") Great will fix it, thx for all your time and help :-)

              – Michael
              Nov 23 '18 at 12:34



















            0














            ok, this is what i should write in the controll!, it doesent work Got an error with the () after new Full so i took it away, can it be the problem?



             public ActionResult channel_index()
            {
            List<Full> model = new List<Full>();
            //you need to do the query with ToList
            var list = db.Full.ToList();

            foreach (var item in list)
            {
            var initedF = new Full
            {
            Channel = item.Channel,
            Program = item.Program
            };
            //f.Channel = item.Channel;
            //f.Program = item.Program;
            model.Add(initedF);
            }
            return View(model);
            }





            share|improve this answer






















              protected by Community Nov 23 '18 at 12:27



              Thank you for your interest in this question.
              Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



              Would you like to answer one of these unanswered questions instead?














              6 Answers
              6






              active

              oldest

              votes








              6 Answers
              6






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              The problem is if you write b.Full you will get IQueryable<Full> but if you want to do the query you should write .toList().



              Updated:



              In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "")



              You can see some another examples how to remove whitespacehttp://www.csharp411.com/remove-whitespace-from-c-strings/



              public ActionResult channel_index()
              {
              List<Full> model = new List<Full>();
              //you need to do the query with ToList
              var list = db.Full.ToList();

              foreach (var item in list )
              {
              var initedF = new Full({
              Channel = Regex.Replace(item.Channel, @"s", ""),
              Program = Regex.Replace(item.Program, @"s", "")
              });
              //f.Channel = item.Channel;
              //f.Program = item.Program;
              model.Add(initedF);
              }
              return View(model);
              }





              share|improve this answer


























              • @Michael please provide TvProgramDBEntities class code

                – Maksym Labutin
                Nov 23 '18 at 11:26











              • Not sure what you mean with Entity framework class, is it the table i posted you mean? Tryed your code but cant still get any data in my view #maksym

                – Michael
                Nov 23 '18 at 11:27











              • could you please share your code in the TvProgramDBEntities class?

                – Maksym Labutin
                Nov 23 '18 at 11:30













              • TvProgramDBEntitities is my databasconnection. My data is stored in table full (class). Cant find any special class code for TVProgramDBEntities, where do i find that in MVC Project? My database have no relationsship to other tables..

                – Michael
                Nov 23 '18 at 11:35













              • Ok. Then do this before foreach var list = db.Full; and send me what will be in the list

                – Maksym Labutin
                Nov 23 '18 at 11:40
















              0














              The problem is if you write b.Full you will get IQueryable<Full> but if you want to do the query you should write .toList().



              Updated:



              In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "")



              You can see some another examples how to remove whitespacehttp://www.csharp411.com/remove-whitespace-from-c-strings/



              public ActionResult channel_index()
              {
              List<Full> model = new List<Full>();
              //you need to do the query with ToList
              var list = db.Full.ToList();

              foreach (var item in list )
              {
              var initedF = new Full({
              Channel = Regex.Replace(item.Channel, @"s", ""),
              Program = Regex.Replace(item.Program, @"s", "")
              });
              //f.Channel = item.Channel;
              //f.Program = item.Program;
              model.Add(initedF);
              }
              return View(model);
              }





              share|improve this answer


























              • @Michael please provide TvProgramDBEntities class code

                – Maksym Labutin
                Nov 23 '18 at 11:26











              • Not sure what you mean with Entity framework class, is it the table i posted you mean? Tryed your code but cant still get any data in my view #maksym

                – Michael
                Nov 23 '18 at 11:27











              • could you please share your code in the TvProgramDBEntities class?

                – Maksym Labutin
                Nov 23 '18 at 11:30













              • TvProgramDBEntitities is my databasconnection. My data is stored in table full (class). Cant find any special class code for TVProgramDBEntities, where do i find that in MVC Project? My database have no relationsship to other tables..

                – Michael
                Nov 23 '18 at 11:35













              • Ok. Then do this before foreach var list = db.Full; and send me what will be in the list

                – Maksym Labutin
                Nov 23 '18 at 11:40














              0












              0








              0







              The problem is if you write b.Full you will get IQueryable<Full> but if you want to do the query you should write .toList().



              Updated:



              In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "")



              You can see some another examples how to remove whitespacehttp://www.csharp411.com/remove-whitespace-from-c-strings/



              public ActionResult channel_index()
              {
              List<Full> model = new List<Full>();
              //you need to do the query with ToList
              var list = db.Full.ToList();

              foreach (var item in list )
              {
              var initedF = new Full({
              Channel = Regex.Replace(item.Channel, @"s", ""),
              Program = Regex.Replace(item.Program, @"s", "")
              });
              //f.Channel = item.Channel;
              //f.Program = item.Program;
              model.Add(initedF);
              }
              return View(model);
              }





              share|improve this answer















              The problem is if you write b.Full you will get IQueryable<Full> but if you want to do the query you should write .toList().



              Updated:



              In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "")



              You can see some another examples how to remove whitespacehttp://www.csharp411.com/remove-whitespace-from-c-strings/



              public ActionResult channel_index()
              {
              List<Full> model = new List<Full>();
              //you need to do the query with ToList
              var list = db.Full.ToList();

              foreach (var item in list )
              {
              var initedF = new Full({
              Channel = Regex.Replace(item.Channel, @"s", ""),
              Program = Regex.Replace(item.Program, @"s", "")
              });
              //f.Channel = item.Channel;
              //f.Program = item.Program;
              model.Add(initedF);
              }
              return View(model);
              }






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 23 '18 at 12:29

























              answered Nov 23 '18 at 10:05









              Maksym LabutinMaksym Labutin

              387314




              387314













              • @Michael please provide TvProgramDBEntities class code

                – Maksym Labutin
                Nov 23 '18 at 11:26











              • Not sure what you mean with Entity framework class, is it the table i posted you mean? Tryed your code but cant still get any data in my view #maksym

                – Michael
                Nov 23 '18 at 11:27











              • could you please share your code in the TvProgramDBEntities class?

                – Maksym Labutin
                Nov 23 '18 at 11:30













              • TvProgramDBEntitities is my databasconnection. My data is stored in table full (class). Cant find any special class code for TVProgramDBEntities, where do i find that in MVC Project? My database have no relationsship to other tables..

                – Michael
                Nov 23 '18 at 11:35













              • Ok. Then do this before foreach var list = db.Full; and send me what will be in the list

                – Maksym Labutin
                Nov 23 '18 at 11:40



















              • @Michael please provide TvProgramDBEntities class code

                – Maksym Labutin
                Nov 23 '18 at 11:26











              • Not sure what you mean with Entity framework class, is it the table i posted you mean? Tryed your code but cant still get any data in my view #maksym

                – Michael
                Nov 23 '18 at 11:27











              • could you please share your code in the TvProgramDBEntities class?

                – Maksym Labutin
                Nov 23 '18 at 11:30













              • TvProgramDBEntitities is my databasconnection. My data is stored in table full (class). Cant find any special class code for TVProgramDBEntities, where do i find that in MVC Project? My database have no relationsship to other tables..

                – Michael
                Nov 23 '18 at 11:35













              • Ok. Then do this before foreach var list = db.Full; and send me what will be in the list

                – Maksym Labutin
                Nov 23 '18 at 11:40

















              @Michael please provide TvProgramDBEntities class code

              – Maksym Labutin
              Nov 23 '18 at 11:26





              @Michael please provide TvProgramDBEntities class code

              – Maksym Labutin
              Nov 23 '18 at 11:26













              Not sure what you mean with Entity framework class, is it the table i posted you mean? Tryed your code but cant still get any data in my view #maksym

              – Michael
              Nov 23 '18 at 11:27





              Not sure what you mean with Entity framework class, is it the table i posted you mean? Tryed your code but cant still get any data in my view #maksym

              – Michael
              Nov 23 '18 at 11:27













              could you please share your code in the TvProgramDBEntities class?

              – Maksym Labutin
              Nov 23 '18 at 11:30







              could you please share your code in the TvProgramDBEntities class?

              – Maksym Labutin
              Nov 23 '18 at 11:30















              TvProgramDBEntitities is my databasconnection. My data is stored in table full (class). Cant find any special class code for TVProgramDBEntities, where do i find that in MVC Project? My database have no relationsship to other tables..

              – Michael
              Nov 23 '18 at 11:35







              TvProgramDBEntitities is my databasconnection. My data is stored in table full (class). Cant find any special class code for TVProgramDBEntities, where do i find that in MVC Project? My database have no relationsship to other tables..

              – Michael
              Nov 23 '18 at 11:35















              Ok. Then do this before foreach var list = db.Full; and send me what will be in the list

              – Maksym Labutin
              Nov 23 '18 at 11:40





              Ok. Then do this before foreach var list = db.Full; and send me what will be in the list

              – Maksym Labutin
              Nov 23 '18 at 11:40













              0














              CREATE TABLE [dbo].[Full] (
              [Id] INT IDENTITY (1, 1) NOT NULL,
              [Channel] NCHAR (50) NULL,
              [Program] NCHAR (50) NULL,
              [Category] NCHAR (50) NULL,
              [Date] NCHAR (50) NULL,
              [Time] NCHAR (50) NULL,
              [Length] NCHAR (10) NULL,
              PRIMARY KEY CLUSTERED ([Id] ASC)
              );





              share|improve this answer




























                0














                CREATE TABLE [dbo].[Full] (
                [Id] INT IDENTITY (1, 1) NOT NULL,
                [Channel] NCHAR (50) NULL,
                [Program] NCHAR (50) NULL,
                [Category] NCHAR (50) NULL,
                [Date] NCHAR (50) NULL,
                [Time] NCHAR (50) NULL,
                [Length] NCHAR (10) NULL,
                PRIMARY KEY CLUSTERED ([Id] ASC)
                );





                share|improve this answer


























                  0












                  0








                  0







                  CREATE TABLE [dbo].[Full] (
                  [Id] INT IDENTITY (1, 1) NOT NULL,
                  [Channel] NCHAR (50) NULL,
                  [Program] NCHAR (50) NULL,
                  [Category] NCHAR (50) NULL,
                  [Date] NCHAR (50) NULL,
                  [Time] NCHAR (50) NULL,
                  [Length] NCHAR (10) NULL,
                  PRIMARY KEY CLUSTERED ([Id] ASC)
                  );





                  share|improve this answer













                  CREATE TABLE [dbo].[Full] (
                  [Id] INT IDENTITY (1, 1) NOT NULL,
                  [Channel] NCHAR (50) NULL,
                  [Program] NCHAR (50) NULL,
                  [Category] NCHAR (50) NULL,
                  [Date] NCHAR (50) NULL,
                  [Time] NCHAR (50) NULL,
                  [Length] NCHAR (10) NULL,
                  PRIMARY KEY CLUSTERED ([Id] ASC)
                  );






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 11:25









                  MichaelMichael

                  33




                  33























                      0














                      enter image description here



                      printscreen of my full table. it have 180 rows and the program fron channel SVT2, TV3, TV4, Kanal5 come later on






                      share|improve this answer
























                      • Good. But what the request return? You can simply check it with var list = db.Full; before foreach loop and send me what will be in the list

                        – Maksym Labutin
                        Nov 23 '18 at 11:54











                      • added som printscreen, hope it give some info ;-)

                        – Michael
                        Nov 23 '18 at 12:18
















                      0














                      enter image description here



                      printscreen of my full table. it have 180 rows and the program fron channel SVT2, TV3, TV4, Kanal5 come later on






                      share|improve this answer
























                      • Good. But what the request return? You can simply check it with var list = db.Full; before foreach loop and send me what will be in the list

                        – Maksym Labutin
                        Nov 23 '18 at 11:54











                      • added som printscreen, hope it give some info ;-)

                        – Michael
                        Nov 23 '18 at 12:18














                      0












                      0








                      0







                      enter image description here



                      printscreen of my full table. it have 180 rows and the program fron channel SVT2, TV3, TV4, Kanal5 come later on






                      share|improve this answer













                      enter image description here



                      printscreen of my full table. it have 180 rows and the program fron channel SVT2, TV3, TV4, Kanal5 come later on







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 23 '18 at 11:49









                      MichaelMichael

                      33




                      33













                      • Good. But what the request return? You can simply check it with var list = db.Full; before foreach loop and send me what will be in the list

                        – Maksym Labutin
                        Nov 23 '18 at 11:54











                      • added som printscreen, hope it give some info ;-)

                        – Michael
                        Nov 23 '18 at 12:18



















                      • Good. But what the request return? You can simply check it with var list = db.Full; before foreach loop and send me what will be in the list

                        – Maksym Labutin
                        Nov 23 '18 at 11:54











                      • added som printscreen, hope it give some info ;-)

                        – Michael
                        Nov 23 '18 at 12:18

















                      Good. But what the request return? You can simply check it with var list = db.Full; before foreach loop and send me what will be in the list

                      – Maksym Labutin
                      Nov 23 '18 at 11:54





                      Good. But what the request return? You can simply check it with var list = db.Full; before foreach loop and send me what will be in the list

                      – Maksym Labutin
                      Nov 23 '18 at 11:54













                      added som printscreen, hope it give some info ;-)

                      – Michael
                      Nov 23 '18 at 12:18





                      added som printscreen, hope it give some info ;-)

                      – Michael
                      Nov 23 '18 at 12:18











                      0














                      enter image description here



                      printscreen when i run the program..






                      share|improve this answer
























                      • Good. I edited my answer. You just need add .ToList() and all should work (var list = db.Full.ToList();). See my answer

                        – Maksym Labutin
                        Nov 23 '18 at 12:17
















                      0














                      enter image description here



                      printscreen when i run the program..






                      share|improve this answer
























                      • Good. I edited my answer. You just need add .ToList() and all should work (var list = db.Full.ToList();). See my answer

                        – Maksym Labutin
                        Nov 23 '18 at 12:17














                      0












                      0








                      0







                      enter image description here



                      printscreen when i run the program..






                      share|improve this answer













                      enter image description here



                      printscreen when i run the program..







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 23 '18 at 12:13









                      MichaelMichael

                      33




                      33













                      • Good. I edited my answer. You just need add .ToList() and all should work (var list = db.Full.ToList();). See my answer

                        – Maksym Labutin
                        Nov 23 '18 at 12:17



















                      • Good. I edited my answer. You just need add .ToList() and all should work (var list = db.Full.ToList();). See my answer

                        – Maksym Labutin
                        Nov 23 '18 at 12:17

















                      Good. I edited my answer. You just need add .ToList() and all should work (var list = db.Full.ToList();). See my answer

                      – Maksym Labutin
                      Nov 23 '18 at 12:17





                      Good. I edited my answer. You just need add .ToList() and all should work (var list = db.Full.ToList();). See my answer

                      – Maksym Labutin
                      Nov 23 '18 at 12:17











                      0














                      enter image description here



                      and the model when i run






                      share|improve this answer
























                      • I found the problem. Please read my answer again =)

                        – Maksym Labutin
                        Nov 23 '18 at 12:29








                      • 1





                        ahh, now i saw it, you mean: Updated: In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "") Great will fix it, thx for all your time and help :-)

                        – Michael
                        Nov 23 '18 at 12:34
















                      0














                      enter image description here



                      and the model when i run






                      share|improve this answer
























                      • I found the problem. Please read my answer again =)

                        – Maksym Labutin
                        Nov 23 '18 at 12:29








                      • 1





                        ahh, now i saw it, you mean: Updated: In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "") Great will fix it, thx for all your time and help :-)

                        – Michael
                        Nov 23 '18 at 12:34














                      0












                      0








                      0







                      enter image description here



                      and the model when i run






                      share|improve this answer













                      enter image description here



                      and the model when i run







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 23 '18 at 12:17









                      MichaelMichael

                      33




                      33













                      • I found the problem. Please read my answer again =)

                        – Maksym Labutin
                        Nov 23 '18 at 12:29








                      • 1





                        ahh, now i saw it, you mean: Updated: In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "") Great will fix it, thx for all your time and help :-)

                        – Michael
                        Nov 23 '18 at 12:34



















                      • I found the problem. Please read my answer again =)

                        – Maksym Labutin
                        Nov 23 '18 at 12:29








                      • 1





                        ahh, now i saw it, you mean: Updated: In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "") Great will fix it, thx for all your time and help :-)

                        – Michael
                        Nov 23 '18 at 12:34

















                      I found the problem. Please read my answer again =)

                      – Maksym Labutin
                      Nov 23 '18 at 12:29







                      I found the problem. Please read my answer again =)

                      – Maksym Labutin
                      Nov 23 '18 at 12:29






                      1




                      1





                      ahh, now i saw it, you mean: Updated: In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "") Great will fix it, thx for all your time and help :-)

                      – Michael
                      Nov 23 '18 at 12:34





                      ahh, now i saw it, you mean: Updated: In the db you have Program with a lot of whitespace, this mean that "SVT1" != "SVT1 ". You need to use Regex.Replace(text, @"s", "") Great will fix it, thx for all your time and help :-)

                      – Michael
                      Nov 23 '18 at 12:34











                      0














                      ok, this is what i should write in the controll!, it doesent work Got an error with the () after new Full so i took it away, can it be the problem?



                       public ActionResult channel_index()
                      {
                      List<Full> model = new List<Full>();
                      //you need to do the query with ToList
                      var list = db.Full.ToList();

                      foreach (var item in list)
                      {
                      var initedF = new Full
                      {
                      Channel = item.Channel,
                      Program = item.Program
                      };
                      //f.Channel = item.Channel;
                      //f.Program = item.Program;
                      model.Add(initedF);
                      }
                      return View(model);
                      }





                      share|improve this answer




























                        0














                        ok, this is what i should write in the controll!, it doesent work Got an error with the () after new Full so i took it away, can it be the problem?



                         public ActionResult channel_index()
                        {
                        List<Full> model = new List<Full>();
                        //you need to do the query with ToList
                        var list = db.Full.ToList();

                        foreach (var item in list)
                        {
                        var initedF = new Full
                        {
                        Channel = item.Channel,
                        Program = item.Program
                        };
                        //f.Channel = item.Channel;
                        //f.Program = item.Program;
                        model.Add(initedF);
                        }
                        return View(model);
                        }





                        share|improve this answer


























                          0












                          0








                          0







                          ok, this is what i should write in the controll!, it doesent work Got an error with the () after new Full so i took it away, can it be the problem?



                           public ActionResult channel_index()
                          {
                          List<Full> model = new List<Full>();
                          //you need to do the query with ToList
                          var list = db.Full.ToList();

                          foreach (var item in list)
                          {
                          var initedF = new Full
                          {
                          Channel = item.Channel,
                          Program = item.Program
                          };
                          //f.Channel = item.Channel;
                          //f.Program = item.Program;
                          model.Add(initedF);
                          }
                          return View(model);
                          }





                          share|improve this answer













                          ok, this is what i should write in the controll!, it doesent work Got an error with the () after new Full so i took it away, can it be the problem?



                           public ActionResult channel_index()
                          {
                          List<Full> model = new List<Full>();
                          //you need to do the query with ToList
                          var list = db.Full.ToList();

                          foreach (var item in list)
                          {
                          var initedF = new Full
                          {
                          Channel = item.Channel,
                          Program = item.Program
                          };
                          //f.Channel = item.Channel;
                          //f.Program = item.Program;
                          model.Add(initedF);
                          }
                          return View(model);
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 23 '18 at 12:27









                          MichaelMichael

                          33




                          33

















                              protected by Community Nov 23 '18 at 12:27



                              Thank you for your interest in this question.
                              Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                              Would you like to answer one of these unanswered questions instead?



                              這個網誌中的熱門文章

                              Academy of Television Arts & Sciences

                              L'Équipe

                              1995 France bombings