Reputation: 283
I currently have the following link that navigates from one view to another:
"<td class='EmployeeTableTD'><a href='personDetails'>" + item.Name + " " + item.Surname + "</a></td>" +
The table is dynamically created in Javascript and gets the data (item) from an ADO model.
I want to attach parameters to pass them through to the controller and then to the view of the next screen.
I have tried taking the usual
'personDetails?myParameter=' + item.Name
type of method, but this caused a 404 error. I also tried inserting a @HTML.ActionLink into the code, but this is also problematic as the intellisense does not recognise 'item' when trying to set the parameters.
Is there a way I can pass dynamic parameters from this view link to the next controller/view?
Controller:
using System;
...
namespace techTest4.Controllers
{
public class HomeController : Controller
{
private TechTestEntities techContext = new TechTestEntities();
public ActionResult personDetails()
{
return View();
}
public ActionResult Index()
{
return View();
}
So my navigation correctly goes to 'Home/personDetails' and the 'personDetails.cshtml' view (which has little in it yet, but needs to output the parameters passed). It arguably should navigate to 'Home/personDetailsController/{someIndexMethod}' where the set up of the next page would be handled.
Config:
routes.MapRoute(
name: "Details",
url: "PeopleDetails/{action}/{id}",
defaults: new
{
controller = "PeopleDetails",
action = "All",
id = UrlParameter.Optional
}
);
Upvotes: 0
Views: 3661
Reputation: 806
You have to specify the parameters you're receiving in your action:
public ActionResult personDetails(String myParameter)
{
return View();
}
Upvotes: 2