开发者

How to take a textbox and print the contents in a url (MVC3)

开发者 https://www.devze.com 2023-02-17 15:41 出处:网络
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 simpl

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

精彩评论

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