开发者

sending parameter to another action as querystring not form parameter

i have a form that have a field which hold query for search and a button to send query value to another action method to perform search. now i want to send this parameter as querystring; not form parameter. but when 开发者_开发问答i click on submit button it's value isn't shown on address bar and sended as form parameter.

<% using (Html.BeginForm("Result", "Search", FormMethod.Post))
       { %>
    <input id="query" name="query" type="text" value="<%: ViewData["InitialQuery"]%>"
        class="search-field" />
    <input id="search" type="submit" value="Search" class="search-button" />
    <%} %>

public ActionResult Result(string query)
    {
        if (string.IsNullOrEmpty(query))
            return RedirectToRoute("SearchEngineBasicSearch");
        var search = new Search();
        var results = search.PerformSearch(query);
        if (results != null && results.Count() > 0)
            return View("Result");
        return View("Not-Found");
    }

URL after clicking on submit button is .../search/result and i want to be .../search/result?query=someQueries

thank in advance ;)


Change FormMethod.Post to FormMethod.Get.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜