I'm new to MVC and LINQ. Currently I faced difficulty on the project and decide to posted up.
My MVC-View that I wanted to achieve
Cut
----------------------------------
1 20%
2 40%
Color
----------------------------------
3 30%
4 50%
Perm
----------------------------------
5 10%
This is some example of my data table
ID Offer Service
-------------------
1 20% Cut
2 40% Cut
3 30% Color
4 50% Color
5 10% Perm
My Controller:
var services = (from ps in db.PS
select ps).Distinct().ToArray();
ViewBag.services = services;
My View:
@foreach (var item in ViewBag.services){
<h3 class="page-header">
@item
</h3>
//Table TAG INSERT Here: ID, Offer, Service
}
PROBLEM comes now, I have no idea on how to populate the data from DB into the view according to their own Service(eg: Cut, Color, Perm) in View
I'm thinking of doing this to store the data according to services in my Controller:
foreach (var i in services){
var servicesdata = (from ps in db.PS
where ps.Service == i
select ps).ToArray();
}
I'm wondering can I push the services data that already according to the services into some kind of array so that I can populate into view?