So, basically the web site shows the user a drop down list to choose a category. The following action is used to let the user select a category and show the items:
public ActionResult SelectResourceCategory()
{
return View(new ResourceModel());
}
[HttpPost]
public ActionResult SelectResourceCategory(ResourceModel rm)
{
Resource r = new Resource();
r.CategoryID = rm.Categories.Id;
List<Resource> GetCourses = new UserBL().GetResourcesByCategoryID(r.CategoryID);
var vRM = new List<ResourceModel>();
foreach (Resource rs in GetCourses)
{
ResourceModel frm = new ResourceModel();
frm.ResourceID = rs.Id;
frm.Title = rs.Title;
frm.Description = rs.Description;
frm.Price = (float)rs.Price;
vRM.Add(frm);
}
return View("ShowResources", vRM);
}
public ActionResult ShowResources()
{
return View();
}
After the user chooses, the webpage then shows the user a list of available resources which the user can buy. Using the link below, I pass the resourceID of the chosen item as parameter:
@Html.ActionLink("Buy", "BuyResource", new RouteValueDictionary(new { id = item.ResourceID }))
and the Action "BuyResource" does the following:
public ActionResult BuyResource(int id)
{
Session["Rid"] = id; //GOTO: RedirectFromPayPal
Resource r = new UserBL().GetResourceByID(id);
return View(r);
}
THE PROBLEM: When the user clicks "Buy", for some reason, the page redirects the user back to the page where he needs to select a category, specifically "SelectResourceCategory" action. It should be redirecting to the "BuyResource" Action and I do not understand why it's not doing so.
EDIT:
The SelectResourceCategory VIEW:
@model SSD.Models.ResourceModel
@{
ViewBag.Title = "SelectResourceCategory";
Layout = "~/Views/Shared/UserPage.cshtml";
}
<h2>SelectResourceCategory</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>ResourceModel</legend>
<div class="editor-field">
@Html.DropDownListFor(model => model.Categories.Id, Model.CategoryList)
@Html.ValidationMessageFor(model => model.Categories.Id)
</div>
<p>
<input type="submit" value="Show available resources" />
</p>
</fieldset>
}
Routing settings:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}