Problème utilisation foreach dans controleur
Bonjour,
Je voudrais faire une boucle avec foreach dans mon controler mais j'obtiens le message
Citation:
foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator
.
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Text;
using MvcApplication4.Models;
namespace MvcApplication4.Controllers
{
[HandleError]
public class HomeController : Controller
{
TextesDBEntities _db;
public HomeController()
{
_db = new TextesDBEntities();
}
public ActionResult Index()
{
HomeController MSG = new HomeController();
TempData["error"] = MSG;
ViewData.Model = _db.TexteSet.ToList();
foreach (var m in ViewData.Model)
{
MvcApplication4.Helpers.TexteAModifier.setTexte(m.Chaine,m.Id);
}
return View();
}
}
} |
J'ai cherché à différents endroits mais rien ne marche.
Est-ce que quelqu'un verrait comment corriger le problème?
Merci.