我的表单具有一个字段,该字段可容纳查询以进行搜索,并且一个按钮将查询值发送到另一个操作方法以执行搜索。现在,我想将此参数作为Querystring发送;不形式参数。但是,当我单击提交按钮时,它的值未显示在地址栏上,并发送为 表单参数.

<% 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为.../搜索/结果,我想成为.../搜索/结果?

预先感谢 ;)

有帮助吗?

解决方案

改变 FormMethod.PostFormMethod.Get.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top