ASP.NET Product Listing I am working on a e-shop in ASP.NET MVC, and I just made the listing of product the way I figured out this night. Is it correct? Or should I make it differently? How?

So this is my Product controller, used for displaying the products from Db.

using WebShop.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebShop.Controllers
{
    public class ProductController : Controller
    {
        private WebShopEntities db = new WebShopEntities();

        public ActionResult Category(int? id)
        {
            int pid = id == null ? 1 : (int)id;  //if requested id is null, set is as 1
            if (db.Categories.Find(pid) == null)  //if category does not exist, return Error
                return View("Error");
            var model = db.Categories.Find(pid).Products.ToList(); //return list of projects in requested category
            return View(model);
        }
    }
}


This is the Category View. 

@using WebShop.Models
    @{
        ViewBag.Title = "Category";
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    &lt;div class="vert-offset-top-2"&gt;
        &lt;div class="list-group col-sm-3"&gt;
            @Html.Partial("Partial/_PartialCategoryMenu")  //display partial view for category menu
        &lt;/div&gt;
        &lt;div class="row"&gt;
            @foreach(Product p in Model)
            {
                @Html.Partial("Partial/_PartialProduct", p)  //display partial view
            }
        &lt;/div&gt;
    &lt;/div&gt;


These are partial Views, which are self-explanatory I hope.
Category partial view

@using WebShop.Models

@using (var db = new WebShopEntities()) {
foreach (var category in db.Categories)
{
    &lt;a href="@Url.Action("Category","Product", new {id = category.id})" class="list-group-item"&gt;@category.name&lt;/a&gt;
}
}


Product partial view

&lt;div class="vert-offset-bottom-1 col-sm-3"&gt;
    &lt;div class="thumbnail"&gt;
        &lt;img src="" class="img-responsive" alt="Product image"&gt;
        &lt;div class="caption"&gt;
            &lt;h3&gt;@Model.name&lt;/h3&gt;
            &lt;h4&gt;@Model.price €&lt;/h4&gt;
            &lt;p&gt;@Model.description&lt;/p&gt;
            &lt;p&gt;&lt;a href="#" class="btn btn-primary" role="button"&gt;To Cart&lt;/a&gt; &lt;a href="@Url.Action("Details", "Product", new {id = @Model.id})" class="btn btn-default" role="button"&gt;Details&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
I would definitely remove the database access from the Category partial view and move it to the Controller (you can add it to the view model or have a separate action for returning them which is even more clean).

Views are supposed to be dumb layouts and not perform any business logic. Removing the database context shouldn't affect the compilation of the views.

Small refactoring suggestion for the Controller:

    public ActionResult Category(int? id)
    {
        var pid = id ?? 1;  //if requested id is null, set is as 1

        var category = db.Categories.Find(pid);

        if (category == null)  //if category does not exist, return Error
            return View("Error");

        var model = category.Products.ToList(); //return list of projects in requested category

        return View(model);
    }


Don't call find twice will save an extra database access which is important and code style wise I would use the ?? operator as you see above.

What the View("Error") is doing? Do you have an error view or is it just raising an exception? In both cases I would be more specific.

I would also make the view strongly typed as it will prevent errors and give you IntelliSense.