I have a view with a textbox and a开发者_如何学JAVA button. I want to take the textbox and take the contents of what a user types in and put it as a "Get" variable in the URL. Does anyone have a simple example of this? I want it to print into a url like this: /Profiles/Search?searchstring=hello
I am using razor built in mvc3 view
If you're using a strongly typed view, you could do:
@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Get))
{
@Html.TextBoxFor(m => m.SearchString)
<input type="submit" value="Search" />
}
Otherwise, with a weakly typed view:
@using(Html.BeginForm("ActionName", "ControllerName", FormMethod.Get))
{
@Html.TextBox("searchstring")
<input type="submit" value="Search" />
}
精彩评论