What I want is that when the schedule form is loaded for the first time (or without data passing), it shows a list of MovieName. When I click on one MovieName, its ID is sent back to controller as an input of a SQL query, then the result is passed back to the view.
Here are what I've done. But I think when I click on the ActionLink, the controller doesnt handle the data passed back as it is not HttpPost. Also, I dont know how to show the new data back in view. Please help!
ScheduleController.cs
[HttpGet]
public ActionResult Index()
{
var schedules = db.Schedules.Include(s => s.Movie)
.OrderByDescending(s => s.Movie.MovieName)
.ToList();
return View(schedules);
}
[HttpPost]
public ActionResult Index(int MovieID)
{
//return ("Clicked");
var schedules = (from s in db.Schedules
orderby s.ShowDate
select s).ToList();
return View(schedules);
}
Schedule/Index
@using Booking_Ticket_Management_System.Models;
@model IEnumerable<Schedule>
@{
ViewBag.Title = "Schedule";
}
<h2>Choose movies</h2>
@using (Html.BeginForm())
{
<div>
@foreach (Schedule schedule in @Model)
{
@Html.ActionLink(schedule.Movie.MovieName, "Index", "Schedule", new { MovieID = schedule.MovieID},null)
<br />
}
<br />
</div>
}