Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Quote:
Good morning all,

I'm crashing in front of this error message (Error: CS0246: Type or namespace name 'ModelReturn' could not be found (are you missing a using directive or assembly reference *?)):
Let me explain :

- Basically in my view I have this declaration at the top of my page (@Model Client) AND in the Controller return View (GestionClients); .... It works.
- In another creation in my view I have this declaration at the top of my page (@model IEnumerable <product>) AND in the Controller return View (db.Tbl_produits.ToList ()); .... It works.

Having said that, now I want to bring the two @Models together in one view.
So I declare a class that I name (MultiModels), here is:


What I have tried:

C#
using System.Collections.Generic;
namespace Site_LsB_MVC.Models
{
    public class MultiModels
    {
        public IEnumerable<Produit> Produits { get; set; }
        public Client Clients { get; set; }
    }
}


Quote:
Dans mon Controller j'ai ce qui suit :


C#
 public class ProdDbContext : Controller
    {
        private Data.ProdDbContext db = new Data.ProdDbContext();
         public static Client cMain;
 
     public ActionResult Index()
        {
            Client GestionClients = new Client();
            cMain = new Client();
            GestionClients.Clients = cMain.Clients = FillList();
 
 
            MultiModels RetourModel = new MultiModels
            {Produits = db.Tbl_produits.ToList(), Clients = GestionClients};
 
 
            return View(RetourModel);
 
        }
}

Et dans ma vue je note : @model RetourModel
Aucun soucis sur les déclarations de mes inputs et les @Html.TextAreaFor, n'y sur le @foreach (var item in Model.Produits).

Par contre dans ma liste d'erreurs j'ai deux codes CS0246 comme indiqué en haut de mon message !

Me manque t'il une déclaration quelconque ?

Merci d'avance pour votre aide.
Posted
Updated 11-May-21 0:56am

1 solution

Use :
@model MultiModels


RetourModel is a variable, not a Type
Cheers
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900