How to make the controller's name hyphen "-" separated?

Shan k

I am able to use the

[ActionName("My-Action-Name")]
public ActionResult MyActionName()
{
    return View();
}

But I am facing a problem in changing the controller's Name. Is there some annotation available to make controller name hyphen (-) separated in MVC 4?

Somewhat like this:

[ControllerName("My-Controller-Name")]
public class MyControllerName : Controller
{

}
aleha

Here is a good answer:

Add custom route handler (in replace part choose how you want to handle hyphens):

public class HyphenatedRouteHandler : MvcRouteHandler
{
    protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        requestContext.RouteData.Values["controller"] = requestContext.RouteData.Values["controller"].ToString().Replace("-", "");
        requestContext.RouteData.Values["action"] = requestContext.RouteData.Values["action"].ToString().Replace("-", "");
        return base.GetHttpHandler(requestContext);
    }
}

and use it in your RouteConfig

routes.Add(
        new Route("{controller}/{action}/{id}",
            new RouteValueDictionary(
                new { controller = "Home", action = "Index", id = UrlParameter.Optional }),
                new HyphenatedRouteHandler())
        );

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

What's the name for hyphen-separated case?

From Dev

Make a json from string separated by hyphen arrow (->)

From Dev

How to make JSON.NET StringEnumConverter use hyphen-separated casing

From Dev

How to make JSON.NET StringEnumConverter use hyphen-separated casing

From Dev

How to convert arrayList to string separated by hyphen

From Dev

How to convert arrayList to string separated by hyphen

From Dev

Referencing object's property name with hyphen

From Dev

How to match single digits and digits separated by a hyphen with string.match?

From Dev

XSL: How can I sort a three digit, hyphen separated value?

From Dev

How do I remove a file in Linux whose name looks like it's ONLY a hyphen, as in "-"

From Dev

How to use hyphen in object property name?

From Dev

How to create field name in django models with hyphen?

From Dev

How to use (- Hyphen) in a variable name in shell?

From Dev

How to create field name in django models with hyphen?

From Dev

How to unzip a file with a hyphen at the beginning of the file name

From Dev

How to replace hyphen (dash) in table name?

From Dev

How to make a part of a JButton's name colored?

From Dev

How to make a part of a JButton's name colored?

From Dev

How to make Javascript type a month's name?

From Dev

how to make comma separated values

From Dev

How to reference SQL Server table via SAS libname with hyphen in name

From Dev

How to add "requires" for artifact having "-"(hyphen) in its name

From Dev

how does ruby webdriver get element with hyphen in <name, value> pair

From Dev

javascript how to make all strings italic after hyphen?

From Dev

Hyphen in column name cassandra

From Dev

Cassandra Keyspace name with hyphen (-)

From Dev

Wix File Name with hyphen

From Dev

Rebuild Index with Hyphen in Name

From Dev

Make directory with leading hyphen

Related Related

  1. 1

    What's the name for hyphen-separated case?

  2. 2

    Make a json from string separated by hyphen arrow (->)

  3. 3

    How to make JSON.NET StringEnumConverter use hyphen-separated casing

  4. 4

    How to make JSON.NET StringEnumConverter use hyphen-separated casing

  5. 5

    How to convert arrayList to string separated by hyphen

  6. 6

    How to convert arrayList to string separated by hyphen

  7. 7

    Referencing object's property name with hyphen

  8. 8

    How to match single digits and digits separated by a hyphen with string.match?

  9. 9

    XSL: How can I sort a three digit, hyphen separated value?

  10. 10

    How do I remove a file in Linux whose name looks like it's ONLY a hyphen, as in "-"

  11. 11

    How to use hyphen in object property name?

  12. 12

    How to create field name in django models with hyphen?

  13. 13

    How to use (- Hyphen) in a variable name in shell?

  14. 14

    How to create field name in django models with hyphen?

  15. 15

    How to unzip a file with a hyphen at the beginning of the file name

  16. 16

    How to replace hyphen (dash) in table name?

  17. 17

    How to make a part of a JButton's name colored?

  18. 18

    How to make a part of a JButton's name colored?

  19. 19

    How to make Javascript type a month's name?

  20. 20

    how to make comma separated values

  21. 21

    How to reference SQL Server table via SAS libname with hyphen in name

  22. 22

    How to add "requires" for artifact having "-"(hyphen) in its name

  23. 23

    how does ruby webdriver get element with hyphen in <name, value> pair

  24. 24

    javascript how to make all strings italic after hyphen?

  25. 25

    Hyphen in column name cassandra

  26. 26

    Cassandra Keyspace name with hyphen (-)

  27. 27

    Wix File Name with hyphen

  28. 28

    Rebuild Index with Hyphen in Name

  29. 29

    Make directory with leading hyphen

HotTag

Archive