开发者

Pass a value from a text box using submit button and post method

开发者 https://www.devze.com 2022-12-23 00:40 出处:网络
I\'m new to mvc, and I\'m having trouble passing the value of a textbox to the controller method. I\'ve got:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号