Note that there are some explanatory texts on larger screens.

plurals
  1. POActionresult doesnt get called by routelink. Formcollection the culprit?
    text
    copied!<p>I am fairly new to MVC. I am trying to set up a search page that searches a database and returns results. The search box is within a Html.BeginForm in my View, and looks like this:</p> <pre><code> &lt;% using (Html.BeginForm()) { %&gt; &lt;%= Html.TextBox("searchBox", null, new { @id = "searchBox" })%&gt; &lt;div id="searchButtonsDiv"&gt; &lt;input type="submit" value="Search" /&gt; &lt;/div&gt; &lt;% } %&gt; //Results are returned in a ul and orgainized //Pagination below &lt;% if (Model.HasPreviousPage) { %&gt; &lt;%= Html.RouteLink("Previous", "SearchResults", new { page = (Model.PageIndex - 1) })%&gt; &lt;% } %&gt; &lt;% if (Model.HasNextPage) { %&gt; &lt;%= Html.RouteLink("Next", "SearchResults", new { formCollection = "", page = (Model.PageIndex + 1) })%&gt; &lt;% } %&gt; </code></pre> <p>I am using a FormCollection to pass to my controller that looks like this:</p> <pre><code> [AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(FormCollection formCollection, int? page) { var searchString = formCollection["searchBox"]; var results = resultsRepository.GetResults(); var paginatedResults = new PaginatedList&lt;Driver&gt;(results, page ?? 0, pageSize); return View(paginatedResults); } </code></pre> <p>So far so good. When I type a word and press the submit button, Index gets called and the database returns accordingly. The ul gets populated with the results, and when there are more than pageSize results (10 in my case), the Next link shows up.</p> <p>When I click "Next", the default page just loads. No pagination or anything like that. I'm pretty sure it has to do with the fact that my Index ActionResult has a FormCollection as a paramater. I thought I read somewhere that only strings/ints can be handled? Here is the MapRoute:</p> <pre><code> routes.MapRoute( "SearchResults", "Drivers/Index/{formCollection}/{page}", new { controller = "Drivers", action = "Index", formCollection = "", page = "" } ); </code></pre> <p>Am I completely missing something or is there a way to handle this? I know I could just use jquery/ajax to send the string contained in the search listbox, but I don't want to do that because later I plan on adding checkbox's as means of filtering searches, etc.</p> <p>I tried several different ways of setting the formCollection's value, including creating a new FormCollection that adds the searchBox, and just passing strings, etc.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload