Aspnetcore.docs: Searchstring not displayed after search

Created on 9 Aug 2018  Â·  2Comments  Â·  Source: dotnet/AspNetCore.Docs

With the implementation for the search textbox, after searching the search results are correctly displayed, but the search textbox is blank. Recommend:

  1. Add public string SearchString { get; set; } to class MovieGenreViewModel
  2. Populate value in Index controller (movieGenreVM.SearchString = searchString;)
  3. Change title search textbox on Index view to <input asp-for="SearchString">

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

P1 Source - Docs.ms

Most helpful comment

Alternatively to making it part of the model, it may be a good opportunity to show how to use ViewData when passing meta-data from page model. ie:

    public async Task OnGetAsync(string movieGenre, string searchString)
    {
        ViewData["searchString"] = searchString;
        //code code code
    }

   Title: <input type="text" name="SearchString" value="@ViewData["searchString"]">

All 2 comments

@aarongoldenthal great suggestion. I'll do that next doc update.

Alternatively to making it part of the model, it may be a good opportunity to show how to use ViewData when passing meta-data from page model. ie:

    public async Task OnGetAsync(string movieGenre, string searchString)
    {
        ViewData["searchString"] = searchString;
        //code code code
    }

   Title: <input type="text" name="SearchString" value="@ViewData["searchString"]">
Was this page helpful?
0 / 5 - 0 ratings