views:

9

answers:

1

Hi, is there any possibility to create a maproute which would use always one method and it won't be necessary to put it in address?

I mean I've got controller with one method (Index) and it displays items depend on methods argument.

public ActionResult Index(string TabName)
    {
        var tab = (from t in BlogDB.Tabs
                   where t.TabName == TabName
                   select t).SingleOrDefault();

        ViewData.Model =(Tab)tab;
        return View();
    }

and what I want is that I can display items putting address "www.example.com/Tabs/TabName" without "/Index/" between Tabs and TabName. I've tried:

    routes.MapRoute(
        "Tabs1",
        "Tabs/{TabName}",
        new { controller = "Tabs", action = "Index", TabName = UrlParameter.Optional }
    );

But it doesn't work.

A: 

do you still have the default route? and if yes is it defined before this one?

Your problem is that asp.net mvc is trying to find the Tabs controller and the Tabname action.

Put this route before the default {controller}/{action} route

Sruly