0

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
                }
            ); 
3
  • Can you show us your controller? Commented May 9, 2017 at 21:59
  • What is the controller and method names your trying to navigate to? Commented May 9, 2017 at 21:59
  • 1
    Your personDetails method doesn't take any parameters. Commented May 9, 2017 at 22:04

1 Answer 1

2

You have to specify the parameters you're receiving in your action:

public ActionResult personDetails(String myParameter)
{
    return View();
}
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, so does that mean I can use the normal 'methodName?parameters=' sort of method if this fix is applied?
Yes, you were missing the parameter in the Action so the browser didn't know exactly which view to render.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.