You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/tutorial-csharp-create-mvc-app.md
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,16 +17,16 @@ ms.date: 07/10/2025
17
17
18
18
# Create a search app in ASP.NET Core
19
19
20
-
In this tutorial, create a basic ASP.NET Core (Model-View-Controller) app that runs in localhost and connects to the hotels-sample-index on your search service. In this tutorial, learn how to:
20
+
In this tutorial, you create a basic ASP.NET Core (Model-View-Controller) app that runs in localhost and connects to the hotels-sample-index on your search service. You learn how to:
21
21
22
22
> [!div class="checklist"]
23
23
> + Create a basic search page
24
24
> + Filter results
25
25
> + Sort results
26
26
27
-
This tutorial puts the focus on server-side operations called through the [Search APIs](/dotnet/api/overview/azure/search.documents-readme). Although it's common to sort and filter in client-side script, knowing how to invoke these operations on the server gives you more options when designing the search experience.
27
+
This tutorial focuses on server-side operations called through the [Search APIs](/dotnet/api/overview/azure/search.documents-readme). Although it's common to sort and filter in client-side script, knowing how to invoke these operations on the server gives you more options when designing the search experience.
28
28
29
-
Sample code for this tutorial can be found in the [azure-search-dotnet-samples](https://github.com/Azure-Samples/azure-search-dotnet-samples/tree/main/create-mvc-app) repository on GitHub.
29
+
You can find sample code for this tutorial in the [azure-search-dotnet-samples](https://github.com/Azure-Samples/azure-search-dotnet-samples/tree/main/create-mvc-app) repository on GitHub.
30
30
31
31
## Prerequisites
32
32
@@ -43,21 +43,21 @@ Sample code for this tutorial can be found in the [azure-search-dotnet-samples](
43
43
44
44
1. Select **ASP.NET Core Web App (Model-View-Controller)**, and then select **Next**.
45
45
46
-
1.Provide a project name, and then select **Next**.
46
+
1.Enter a project name, and then select **Next**.
47
47
48
48
1. On the next page, select **.NET 9.0**.
49
49
50
-
1. Accept the defaults.
50
+
1. Accept the default settings.
51
51
52
52
1. Select **Create**.
53
53
54
54
### Add NuGet packages
55
55
56
-
1. On Tools, select **NuGet Package Manager** > **Manage NuGet Packages for the solution**.
56
+
1. On the **Tools** menu, select **NuGet Package Manager** > **Manage NuGet Packages for the solution**.
57
57
58
58
1. Browse for `Azure.Search.Documents` and install the latest stable version.
59
59
60
-
1. Browse for and install the `Microsoft.Spatial` package. The sample index includes a GeographyPoint data type. Installing this package avoids run time errors. Alternatively, remove the "Location" field from the Hotels class if you don't want to install the package. That field isn't used in this tutorial.
60
+
1. Browse for and install the `Microsoft.Spatial` package. The sample index includes a `GeographyPoint` data type. Installing this package avoids run time errors. Alternatively, remove the "Location" field from the `Hotels` class if you don't want to install the package. That field isn't used in this tutorial.
61
61
62
62
### Add service information
63
63
@@ -74,13 +74,13 @@ Modify `appsettings.json` to specify your search service and [query API key](sea
74
74
75
75
You can get the service URL and API key from the Azure portal. Because this code is querying an index and not creating one, you can use a query key instead of an admin key.
76
76
77
-
Make sure to specify a search service that has the hotels-sample-index.
77
+
Make sure to specify a search service that has the `hotels-sample-index`.
78
78
79
79
## Add models
80
80
81
-
In this step, create models that represent the schema of the hotels-sample-index.
81
+
In this step, you create models that represent the schema of the hotels-sample-index.
82
82
83
-
1. In Solution explorer, right-select **Models** and add a new class named "Hotel" for the following code:
83
+
1. In Solution Explorer, right-select **Models** and add a new class named "Hotel" for the following code:
84
84
85
85
```csharp
86
86
usingAzure.Search.Documents.Indexes.Models;
@@ -218,9 +218,9 @@ In this step, create models that represent the schema of the hotels-sample-index
218
218
219
219
For this tutorial, modify the default `HomeController` to contain methods that execute on your search service.
220
220
221
-
1. In Solution explorer under **Models**, open `HomeController`.
221
+
1. In Solution Explorer under **Models**, open `HomeController`.
222
222
223
-
1. Replace the default with the following content:
223
+
1. Replace the default content with the following code:
224
224
225
225
```csharp
226
226
usingAzure;
@@ -322,9 +322,9 @@ For this tutorial, modify the default `HomeController` to contain methods that e
322
322
323
323
## Modify the view
324
324
325
-
1. In Solution explorer under **Views** > **Home**, open `index.cshtml`.
325
+
1. In Solution explorer, under **Views** > **Home**, open `index.cshtml`.
326
326
327
-
1. Replace the default with the following content:
327
+
1. Replace the default content with the following code:
328
328
329
329
```razor
330
330
@model HotelDemoApp.Models.SearchData;
@@ -393,7 +393,7 @@ For this tutorial, modify the default `HomeController` to contain methods that e
393
393
394
394
## Run the sample
395
395
396
-
1. Press **F5** to compile and run the project. The app runs on local host and opens in your default browser.
396
+
1. Press **F5** to compile and run the project. The app runs on localhost and opens in your default browser.
397
397
398
398
1. Select **Search** to return all results.
399
399
@@ -405,7 +405,7 @@ In the next several sections, modify the **RunQueryAsync** method in the `HomeCo
405
405
406
406
Index field attributes determine which fields are searchable, filterable, sortable, facetable, and retrievable. In the hotels-sample-index, filterable fields include Category, Address/City, and Address/StateProvince. This example adds a [$Filter](search-query-odata-filter.md) expression on Category.
407
407
408
-
A filter always executes first, followed by a query assuming one is specified.
408
+
A filter always executes first, followed by a query, assuming you specify one.
409
409
410
410
1. Open the `HomeController` and find the **RunQueryAsync** method. Add [Filter](/dotnet/api/azure.search.documents.searchoptions.filter) to `var options = new SearchOptions()`:
411
411
@@ -444,7 +444,7 @@ For more information about filter expressions, see [Filters in Azure AI Search](
444
444
445
445
In the hotels-sample-index, sortable fields include Rating and LastRenovated. This example adds an [$OrderBy](/dotnet/api/azure.search.documents.searchoptions.orderby) expression to the Rating field.
446
446
447
-
1. Open the `HomeController` and replace **RunQueryAsync** method with the following version:
447
+
1. Open the `HomeController` and replace the **RunQueryAsync** method with the following version:
@@ -478,6 +478,6 @@ For more information about sorting, see [OData $orderby syntax in Azure AI Searc
478
478
479
479
## Next step
480
480
481
-
In this tutorial, you created an ASP.NET Core (MVC) project that connected to a search service and called Search APIs for server-side filtering and sorting.
481
+
In this tutorial, you created an ASP.NET Core (MVC) project that connects to a search service and calls Search APIs for server-side filtering and sorting.
482
482
483
-
To add client-side code that responds to user actions, use a React template in your solution: [C# Tutorial: Add search to a website with .NET](tutorial-csharp-overview.md)
483
+
To add client-side code that responds to user actions, use a React template in your solution: [C# Tutorial: Add search to a website with .NET](tutorial-csharp-overview.md).
0 commit comments