views:

211

answers:

1

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 manually 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

A: 

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" />

Alice in wonderland
I've been very stupid. just moved the name="id" from the button to the text box - so <input type="text" name="id" /> <input type="submit" value="search" /> and it works fine.
Alice in wonderland