Pass a value from a text box using submit button and post method
I'm new to mvc, and I'm having trouble passing the value of a textbox to the controller method.
I've got:
in the aspx page:
<form action="/Search" method="post" > <input type="submit" value="search" name="id" />
global.asax:
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}",
// URL with parameters new { controller = "myController", action = "Search", id = "" } // Parameter defaults
the url I need is
myController/Search/mySearchTerm
when I type this in man开发者_如何学Goually it works fine. But when I press the submit button the url I get is:
myController/Search/Search
If I change the form method to get, I get
myController/Search/Search?id=search
I missed out the textbox from the code at the top.
What I meant to put in was:
<form action="/Search" method="post" > <input type="text" /> <input type="submit" value="search" name="id" />
精彩评论