0

How do I design my URL to match my function like this:

public ActionResult GetStuff(string name, string address, double latitude, double longitude)
{ }

1 Answer 1

3

Add a route with a signature that has all those parameters in it.

routes.MapRoute("myRoute",
                "{controller}/{action}/{name}/{address}/{latitude}/{longitude}",
                new { controller = "Home", 
                      action = "GetStuff", 
                      latitude=0.0, 
                      longitude =0.0, address="", name = "" }
           );

If you just intend to POST data to that action method, then the parameter names in your method signature can just match named input fields on your form instead.

Sign up to request clarification or add additional context in comments.

1 Comment

It will also work with the default route, by putting all the extra values as query values: /controller/action?name=a&address=b&latitude=c&longitude=d

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.