I'm very new to c#
I have the following linq query:
public GetAllProducts[] AllProducts(int status)
{
try
{
using (UserDataDataContext db = new UserDataDataContext())
{
return db.mrobProducts.Where(x => x.Status == status).Select(x => new GetAllProducts { Name = x.Name, Desc = x.Description, Price = x.Price }).OrderBy(x => x.Name).ToArray();
}
}
catch
{
return null;
}
}
All I want to be able to do is call this from my controller and create a list for each product group returned and load it into my view.
My controller is as follows, but I have no clue how to create a list, and pass it to my view, I'm very confused.
public ActionResult Index(GetAllProducts allProductsModel)
{
var webService = new DaveyServiceClient();
webService.AllProducts(1);
var allProducts = webService2.AllProducts();
return View("../Private/Index", allProducts);
}
webService2
? Why don't you use results ofwebService.AllProducts(1);
? Does it return any results? Why do you mute all exceptions? – Ilya Luzyanin yesterday