views:

281

answers:

1

Has anyone come across something like this before? Basically, I have an action on a controller that merely queries the database via a repository pattern, adds some data to the ViewData then returns the View. But for some reason this action is being called 4 times per request.

The whole action itself is only about 10 lines long:

public ActionResult Details(int id, string slug) {
    Product p = productRepository.GetProduct(id);

    IEnumerable<Image> imgs = productRepository.GetImages(p.ProductId);
    if (imgs.Count() > 0) {
        ViewData["MainImage"] = imgs.First();
        ViewData["Images"] = imgs;
    }

    Brand brand = productRepository.GetBrand(p.ProductId);
    ViewData["Brand"] = brand;

    var categories = productRepository.GetCategories(p.ProductId, true);
    ViewData["ProductCategories"] = categories;

    return View("Details", p);
}

Also, the routes defined in my Global.asax are as follows:

routes.MapRoute(
    "SlugsAfterId",
    "{controller}.mvc/{action}/{id}/{slug}",
    new { controller = "Products", action = "Browse", id = "" }
);

// The default route that comes with ASP.NET MVC
routes.MapRoute(
    "Default",                                              // Route name
    "{controller}.mvc/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
);

Can anyone shed any light on this please? I am completely stumped.

+5  A: 

Looks like those requests might be client-side requests like images, css or js files.

Chad Moran
Thanks - it was all down to some images with missing src attributes.
Ian Oxley
Yeah sure, I've had this happen to me before too. : )
Chad Moran