Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to display a search form and its results in the same page?
    primarykey
    data
    text
    <p>Suppose I have a simple search form with a textbox. And upon submitting the form I send the contents of the textbox to a stored procedure which returns to me the results. I want the results to be displayed on the same page the form was, except just below it.</p> <p>Right now I'm doing the following but it's not working out exactly the way I want:</p> <p>"Index" View of my SearchController</p> <pre><code>@using (Html.BeginForm("SearchResults", "Search", FormMethod.Post, new { @class = "searchform" }))`{ &lt;fieldset&gt; &lt;legend&gt;Name&lt;/legend&gt; &lt;div class="editor-label"&gt; @Html.Label("Search") &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.TextBox("Name") &lt;/div&gt; &lt;input type="submit" value="Search" class="formbutton" /&gt; &lt;/fieldset&gt; @{ Html.RenderPartial("SearchResults", null); </code></pre> <p>This is my "SearchResults" View:</p> <pre><code>@model IEnumerable&lt;MyProject.Models.spSearchName_Result&gt; &lt;table&gt; @foreach (var item in Model) { &lt;tr&gt; &lt;td&gt; @item.Name &lt;/td&gt; &lt;/tr&gt; } &lt;/table&gt; </code></pre> <p>This is my Controller:</p> <pre><code> // GET: /Search/SearchResult [HttpPost] public ActionResult SearchResult(FormCollection collection) { var result = myentity.spSearchName(collection["Name"]); return PartialView("SearchResults", result); } </code></pre> <p>I can only seem to get the results to display on an entirely new page (not being embedded as a partial view), or I get an error when I load the search page because there are no results (since I hadn't searched yet).</p> <p>Is there any better way to achieve what I'm trying to do? I feel like I'm going against some of the best practices in MVC.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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