user625351
user625351

Reputation: 261

Asp.Net MV3 Razor List Filter

I am new to MV3 Razor development, so my question is about getting started doing what I am attempting to do.

I have a page called _Layout.cshtml. This page starts out by display a View of Index.cshtml that has a model: @model IEnumerable<Sample.Models.Product>. This is a Northwind database sample that displays a page of Products.

Now in my _Layout.cshtml page, I want either a listbox or dropdownlistbox that would list Categories. When a Category was selected from the list, the Products would be filtered to display only the Products in that Category.

I have tried creating a new page and displaying it using using @RenderPage, with no luck. It seems like the list would need to be displayed in a form, so I was looking at @Html.BeginForm but that is where I got lost.

Any help would be appreciated.

Upvotes: 0

Views: 949

Answers (1)

Stuart
Stuart

Reputation: 66882

I think you need to step back and read a little more about Razor and indeed about ASP.Net MVC.

If you follow through a tutorial like NerdDinner for MVC or ScottGu for Razor, then this will help you work forwards.

At a basic level:

  • the _Layout.cshtml is like a "master page" for your app - it should contain only the common layout elements for all your pages.

  • the Index.cshtml page is where you can put the listbox or dropdown list - take a look around for samples that use @Html.DropDownListFor()

Razor and MVC are superb - hope you enjoy learning and using them.

Upvotes: 1

Related Questions