Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 视图数据中的对象列表,从控制器到视图_C#_Asp.net_Asp.net Mvc_Razor - Fatal编程技术网

C# 视图数据中的对象列表,从控制器到视图

C# 视图数据中的对象列表,从控制器到视图,c#,asp.net,asp.net-mvc,razor,C#,Asp.net,Asp.net Mvc,Razor,我是ASP.NETMVC的初学者。 我正试图在我的视图上打印来自控制器的对象列表 这是我的控制器: namespace PhoneTeleX.Controllers { public class SondageController : Controller { Guid idSondage; bool termine; int TEC_ID; string TQ_Libelle; string lblEntrepriseCliente; publ

我是ASP.NETMVC的初学者。 我正试图在我的视图上打印来自控制器的对象列表

这是我的控制器:

namespace PhoneTeleX.Controllers
{
public class SondageController : Controller
{
    Guid idSondage;
    bool termine;
    int TEC_ID;
    string TQ_Libelle;
    string lblEntrepriseCliente;

    public Guid IdSondage { get => idSondage; set => idSondage = value; }
    public bool Termine { get => termine; set => termine = value; }
    public int TEC_ID1 { get => TEC_ID; set => TEC_ID = value; }
    public string TQ_Libelle1 { get => TQ_Libelle; set => TQ_Libelle = value; }
    public string LblEntrepriseCliente { get => lblEntrepriseCliente; set => lblEntrepriseCliente = value; }

    public SondageController(Guid leID, bool leTermine, int leTEC, string leLibelle,string laEntreprise)
    {
        IdSondage = leID;
        Termine = leTermine;
        TEC_ID1 = leTEC;
        TQ_Libelle1 = leLibelle;
        lblEntrepriseCliente = laEntreprise;
    }

    public SondageController() { }

    public ActionResult SelectionSondage()
    {
        ViewData["Sondages"] = DAOSelectionSondage.refreshSondages();
        return View();
    }
}
}
public ActionResult SelectionSondage()
    {
        //ViewData["Sondages"] = DAOSelectionSondage.refreshSondages();
        ViewData["test"] = "bonjour ceci est un test";
        ViewData["listeSondages"] = DAOSelectionSondage.refreshSondages();
        return View("SelectionSondage");
    }
这是我的看法

@{
ViewBag.Title = "SelectionSondage";
}

<html>
<head>
<meta charset="utf-8" />
<title>PhoneTeleX</title>
@{
ViewBag.Title=“SelectionSondage”;
}
电话电报
十四行诗精选集&Séselection de Sondages

<div>
    <input id="Text1" type="text" placeholder="Tapez ici le code ou nom du sondage désiré..." /> <button class="waves-effect waves-light btn" style="background-color: #008CBA; margin-left : 1.5%;" runat="server" OnClick="LogIn" Value="Rechercher">Rechercher</button>
</div>
<br />
<br />
<div>

    <!-- Affichage par table row de chaque Sondage-->
    <table>
     @foreach (SondageController myObject in ViewData["Sondage"])
    {
       @myObject.lblEntrepriseCliente; //this doesn't work, 
    }
    </table>
</div>

回收机


@foreach(ViewData[“Sondage”]中的SondageControl myObject) { @myObject.lblentrepriseclient;//这不起作用, }

正如您所看到的,我的控制器中的SelectionSondage方法返回了我从SQLServerDatabase创建的对象列表(我在此项目中没有使用EntityFramework)。 我的最终目标是打印您在我的视图中看到的对象内容。 这就是为什么我想将我的对象列表放入ViewData中,以便最终在视图中显示它们


你能帮我吗?

好的,最后我不得不这样做=>

我的控制器:

namespace PhoneTeleX.Controllers
{
public class SondageController : Controller
{
    Guid idSondage;
    bool termine;
    int TEC_ID;
    string TQ_Libelle;
    string lblEntrepriseCliente;

    public Guid IdSondage { get => idSondage; set => idSondage = value; }
    public bool Termine { get => termine; set => termine = value; }
    public int TEC_ID1 { get => TEC_ID; set => TEC_ID = value; }
    public string TQ_Libelle1 { get => TQ_Libelle; set => TQ_Libelle = value; }
    public string LblEntrepriseCliente { get => lblEntrepriseCliente; set => lblEntrepriseCliente = value; }

    public SondageController(Guid leID, bool leTermine, int leTEC, string leLibelle,string laEntreprise)
    {
        IdSondage = leID;
        Termine = leTermine;
        TEC_ID1 = leTEC;
        TQ_Libelle1 = leLibelle;
        lblEntrepriseCliente = laEntreprise;
    }

    public SondageController() { }

    public ActionResult SelectionSondage()
    {
        ViewData["Sondages"] = DAOSelectionSondage.refreshSondages();
        return View();
    }
}
}
public ActionResult SelectionSondage()
    {
        //ViewData["Sondages"] = DAOSelectionSondage.refreshSondages();
        ViewData["test"] = "bonjour ceci est un test";
        ViewData["listeSondages"] = DAOSelectionSondage.refreshSondages();
        return View("SelectionSondage");
    }
我的看法是:

 @foreach (var SondageController in ViewData["listeSondages"] as List<PhoneTeleX.Controllers.SondageController>)
    {
        <p>@SondageController.LblEntrepriseCliente</p>
    }
@foreach(ViewData[“ListSondages”]中的var SondageControl作为列表)
{
@SondageControl.lblentrepriseClient

}
DAOSelectionSondage.refreshSondages返回什么?当你说这不起作用时,这是什么意思?您是否收到任何错误消息?如果有的话,那是什么?@Shyju DAOSelectionSondage.refreshSondages,这个方法返回我从数据库中创建的对象列表,当我说“这不起作用”时,是因为它应该是这样的词,但它不起作用