Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beginner Question #6141

Closed
wcski opened this issue Apr 30, 2018 — with docs.microsoft.com · 8 comments
Closed

Beginner Question #6141

wcski opened this issue Apr 30, 2018 — with docs.microsoft.com · 8 comments
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue

Comments

Copy link

wcski commented Apr 30, 2018

Hello, and thanks for the documentation. I have a quick question about adding search by genre.

The following code allows you to search by title and genre and seems to be a much simpler approach.

`public async Task Index(string searchString)
{
var movies = _context.Movie.AsQueryable();

        if (!String.IsNullOrEmpty(searchString))
        {
            movies = movies.Where(movie => movie.Title.Contains(searchString) || movie.Genere.Contains(searchString));
        }

        return View(await movies.ToListAsync());
    }`

Is there a reason why I should do all of what the documentation describes, or was it just for practice' sake?


Document Details

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

@Rick-Anderson
Copy link
Contributor

Per the article
However, you can't expect users to modify the URL every time they want to search for a movie. So now you'll add UI elements to help them filter movies.

@wcski
Copy link
Author

wcski commented Apr 30, 2018

Sorry, I don't see how that answer is relevant. That line from the article is in reference to querying without a search UI element. With the code in my original question there is no need to modify the URL.

No big deal, I was more just curious than anything.

@Rick-Anderson
Copy link
Contributor

You could use that query. You'd also need to use a POST to bookmark the query. WIthout UI, how would the user know to hack the URL for a search.

@wcski
Copy link
Author

wcski commented Apr 30, 2018

I think there's a miscommunication. I may not have asked my question in the most clear way.

The section "Adding Search by genre" comes after the section in which you add the search bar UI. So we can search for Movies by title by using the search bar. Now, we want to add the ability to search by genre.

It was not immediately clear why adding an additional model to the project is necessary to search by genre when you can just include it in the Where statement. I apologize if this question / discussion is not appropriate for this forum. Thanks for your responses.

@Rick-Anderson
Copy link
Contributor

@wcski no problem. I think the Razor Pages version does a better job of explaining it, and the code is simpler. The view model is build into Razor Pages, one of the advantages it has over MVC.

BTW, why are you doing the MVC tutorial and not the Razor Pages version?

@Rick-Anderson Rick-Anderson reopened this Apr 30, 2018
@Rick-Anderson
Copy link
Contributor

@wcski Your search does an or, but the search is an and.
The view model needs to contain the list of genres and the specific genre selected.

@Rick-Anderson Rick-Anderson added the Source - Docs.ms Docs Customer feedback via GitHub Issue label Apr 30, 2018
@wcski
Copy link
Author

wcski commented Apr 30, 2018

Ah. I didn't look close enough. I see now that the tutorial has you create a select list (so you can filter by Genre and Title, like you said.) I told you it was a beginner question! Thanks for your help.

As for Razor vs MVC - I have already done the Razor pages tutorial. I am doing the MVC tutorial because the projects I will be working on at work are MVC and not Razor pages.

@wcski wcski closed this as completed Apr 30, 2018
@Rick-Anderson
Copy link
Contributor

@wcski Thanks for the info. I added it to #6146 and I'll add a link to it to the tutorials.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

2 participants