In my project, there are two controllers namely Home controller and Hotel controller.I have used view model to combine two model classes.Bellow I have Add my controllers.
Home Controller
public ActionResult Index(){
List<ImageData> details = new List<ImageData>();
var sp_details = (from s in db.service_provider
join p in db.pictures on s.SPID equals p.SPID
join c in db.cities on s.City_ID equals c.City_ID
select new { s.SPID, s.Sp_name, s.Sp_rate, s.service_type, c.Cityname, p.pic }).OrderByDescending(s => s.Sp_rate).Where(p => p.service_type == "Restaurant").Take(3).ToList();
foreach (var item in sp_details)
{
ImageData SpView = new ImageData(); // ViewModel
SpView.SPID = item.SPID;
SpView.Sp_name = item.Sp_name;
SpView.Cityname = item.Cityname;
SpView.Sp_rate = item.Sp_rate;
SpView.pic = item.pic;
details.Add(SpView);
}
return View(details);
}
Hotel controller
public ActionResult Details(int id = 0)
{
List<ImageData> details = new List<ImageData>();
var sp_details = (from s in db.service_provider
join p in db.pictures on s.SPID equals p.SPID
join c in db.cities on s.City_ID equals c.City_ID
where s.SPID == id
select new ImageData()
{
Sp_name = s.Sp_name,
Sp_location = s.Sp_location,
Cityname = c.Cityname,
service_type = s.service_type,
Sp_description = s.Sp_description,
Sp_rate = s.Sp_rate,
Sp_web = s.Sp_web,
Cnt_wh = s.Cnt_wh,
pic = p.pic
});
if (details == null)
{
return HttpNotFound();
}
return View(sp_details);
}
below is part of Index view.I have passed id value to Details action method in Hotel Controller.
<p class="name">@Html.ActionLink(item.Sp_name, "Details","Hotel", new { id = item.SPID })</p>
but value not passed and not display details of Details Action method in Hotel Controller.Since I'm new to mvc 4 I couldn't able to find the mistake.