New to MVC, working on an MVC application where the users do searching on the home page based on dates and location then the service returns the desired product records that I am filling to the generic list then I display those records on another view, now what I want to do is that the user be able to pick one product and do product request.
public ActionResult Index()
{
DateTime dt = System.DateTime.Now.AddDays(7);
var m = (from i in Enumerable.Range(0, 12)
let now = DateTime.Now.AddMonths(i)
select now.Month + " " + now.ToString("MMMM") + " " + now.Year.ToString()).ToList();
ViewBag.day = dt.Day;
ViewBag.b = m;
return View();
}
[HttpPost]
public ActionResult Index(DateTime PickUpDate, string location)
{
//fill data from service
TempData["CollectionTemp"] = CollectionList;
return RedirectToAction("Result");
}
public ActionResult Result()
{
List<myCollection> CollectionResult = new List<myCollection>();
CollectionResult = TempData["CollectionTemp"] as List<myCollection>;
return View(CollectionResult);
}
public class myCollection
{
public Datetime date { get; set; }
public string location { get; set; }
}
On the result view i am displaying the records using razor
@if (Model != null)
{
foreach (var prd in Model)
{
fill the table with data
}
}
now what I want to do to is to create a link for each product that redirects to a new view all details are shown for that particular product. How ? links are welcomed
This is quite a common thing to do – there are a bunch of tutorials out there – this one is quite comprehensive: http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/getting-started-with-mvc3-part1-cs (part 5 is where it goes into this particular bit: http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/getting-started-with-mvc3-part5-cs).
In essence what you could do is create an actionlink that passes back the ID of the item that you are editing to an action method on a controller that then gets all the details for that item and returns a view to edit it.