0

In ASP.NET MVC i have a route /search/{what}/{where}/{pagenr}/

And on my homepage i have 2 text inputs, in which i want the user to type something like:

text1: apples text2: spain.

If i use FormMethod.Post, this works fine, but i dont get the correct Url. I just get /search. In some other post someone mentioned to use FormMethod.Get, but then i get my posted values in querystring form, which is not what i want.

Can anyone tell me how i go from that input form, to the url that matches my route?

Of course i can do that with javascript. But i was thinking that there should be a better, MVC way of doing this?

2 Answers 2

1

If you dont want to use javascript you will need to do your regular http post and then redirect inside your action

return RedirectToAction("Search", new { What = "..", Where = "..", Pagenr = ".." });

Mind you, if your using ajax forms this wont work and i would recommend doing a javascript navigation.

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

1 Comment

Thanks. That was the answer i was looking for.
0

According to W3C, GET forms have to use query strings (starts with ? and separated with &).

The only way to transform query strings to url segment is JavaScript.

Or you can just forget the segment built route.

Comments

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.