Hello,
I am trying to create a web application mvc asp dotnet 4 razor.
I would like to put multiple views in a model.
To make it clearer, here is my Model, my eyesight and my controller.
My Model: two tables : Malades and Consultations
public DbSet Malades { get; set; }
public DbSet Consultations { get; set; }
My Controller:
public ActionResult Index()
{
if (User.Identity.IsAuthenticated)
{
return View();
}
return RedirectToAction("Login", "Account");
}
My ContentViewModel:
public class ViewModelProfil
{
public List Malades { get; set; }
public List Consultations { get; set; }
}
My view:
...
@foreach(var item in Model.Malades)
{
@Html.DisplayNameFor(modelItem => item.Nom)
}
@foreach(var item in Model.Consultations)
{
@Html.DisplayNameFor(modelItem => item.Nombre)
}
...
I want to clarify that the data is not manually integrate into the database, but it is a user who filled out a form for the data to be stored in the database.
I did several searches su google, but I fall on tutorials that show how to do it perfectly, but the data are filled manually (Example : http://www.codeproject.com/Articles/687061/Multiple-Models-in-a-View-in-ASP-NET-MVC-MVC).
Thank you for your help.
Ramsès Zogning IIPosted Feb 4, 2015, 3:05 AM
May Be I explain evil mo problem. So how I could apply the solution that is in the link found below. knowing that the data are not reported in the tables manually, but rather with a form. All models, views and controller are made. But how to display multiple models in one view?
Ps: The method I chose was : Passing Multiple Models using ViewModel
Link : http://www.codeproject.com/Articles/687061/Multiple-Models-in-a-View-in-ASP-NET-MVC-MVCRamsès Zogning IIPosted Feb 4, 2015, 2:59 AM
Exemple :
SICKS : SICKS:
Ramses Suraj
19 years old 20 Years Old
Belgium San Adreas
Name Born Countries
Ramses 19 Belgium
All éléments of table SICKS are not displayed in the views who are the two model (SICK and Consultations)
Suraj SahooPosted Jan 28, 2015, 2:43 AM
You can use the ViewBag property to store the data and show in the View. Code snippet below:
In the controller, fetch all the records required from the db using the context object like
ViewBag.SickData = The data fetched from db;
Viewbag.ConsultationData = The data for Consultation from db;
return View();
Before that make sure you have a viewmodel for sick as well as Consultation.
Then in the View you can use as below. If the ViewBag contain list of data.
@
{
Ramsès Zogning IIPosted Jan 27, 2015, 10:55 AM
Ramsès Zogning IIPosted Jan 27, 2015, 10:42 AM
Suraj SahooPosted Jan 27, 2015, 10:34 AM
I hope you understand.
Thanks.