0

i have defined a route as below:

context.MapRoute("SearchEngineWebSearch", "search/web/{query}/{index}/{size}",
                            new
                            {
                                controller = "search",
                                action = "web",
                                query = "",
                                index = 0,
                                size = 5
                            });

and action method to handle request match with that:

public System.Web.Mvc.ActionResult Web(string query = "", int index = 0, int size = 5)
    {
        if (string.IsNullOrEmpty(query))
            return RedirectToRoute("SearchEngineBasicSearch");
        var search = new Search();
        var results = search.PerformSearch(query, index, size);
        ViewData["Query"] = query;
        if (results != null && results.Count() > 0)
        {
            ViewData["Results"]= results;
            return View("Web");
        }
        else return View("Not-Found");
    }

and form to sent parameter to action method:

<% using (Html.BeginForm("Web", "Search", FormMethod.Post))
       { %>
    <input name="query" type="text" value="<%: ViewData["Query"]%>" class="search-field" />
    <input type="submit" value="Search" class="search-button" />
    <input type="hidden" name="index" value="2" />
    <input type="hidden" name="size" value="2" />
    <%} %>

now after click on submit and sending value to action method all route values updated but url values still is equals to first time of sending parameter. for example if i sent for first time request such as http://localhost/search/web/google and for next time http://localhost/search/web/yahoo, query parameter which passed to action method is yahoo but url after postback is http://localhost/search/web/google still!

can anybody help me plz? ;)

1 Answer 1

1

Try something like

return RedirectToAction("Web", 
   new { query = query, index = index, size = size}); 

instead of return View("Web");.

Also, note that you should perform a GET instead of a POST. And the index and size parameters may be ommitted if they were submitted with the default values.

Sign up to request clarification or add additional context in comments.

1 Comment

sorry, because this cause unlimited redirection! and also if i change form-method from post to get, then it generate url which parameters passed as querystring and i won't that ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.