I may be going about this the wrong way but I’m selecting a list from the many side of a category which works fine but I also want the category name from the one side of the category. I’m trying to get that and put it into ViewBag below.
public ActionResult Search(int id)
{
//ViewBag.CoastName = …
var beaches = (from c in db.Beaches
where c.CoastLineFK == id
orderby c.BeachSuburb
select c);
return View(beaches);
}
If this is the/a correct way to do it, can someone help fill in the gaps here?
Edit:
Iv'e got it working like this,
public ActionResult Search(int id)
{
var metainfo = (from c in db.CoastLines
where c.CoastLineID == id
select c).First();
ViewBag.Title = metainfo.CoastLineName.ToString();
var beaches = (from c in db.Beaches
where c.CoastLineFK == id
orderby c.BeachSuburb
select c);
return View(beaches);
}
Is this a good way to do it, or is there a better way?
bojangles
Participant
974 Points
642 Posts
Selecting Category name from the one side while selecting a list from the many side
Apr 25, 2012 02:31 AM|LINK
Hi,
I may be going about this the wrong way but I’m selecting a list from the many side of a category which works fine but I also want the category name from the one side of the category. I’m trying to get that and put it into ViewBag below.
public ActionResult Search(int id) { //ViewBag.CoastName = … var beaches = (from c in db.Beaches where c.CoastLineFK == id orderby c.BeachSuburb select c); return View(beaches); }If this is the/a correct way to do it, can someone help fill in the gaps here?
Edit:
Iv'e got it working like this,
public ActionResult Search(int id) { var metainfo = (from c in db.CoastLines where c.CoastLineID == id select c).First(); ViewBag.Title = metainfo.CoastLineName.ToString(); var beaches = (from c in db.Beaches where c.CoastLineFK == id orderby c.BeachSuburb select c); return View(beaches); }Is this a good way to do it, or is there a better way?
Cheers,
Mike.