Search code examples
regexasp.net-mvcasp.net-mvc-routing

Check any string except space - MVC routing


With this code, we are forcing to check only numbers:

routes.MapRoute("ById", "{id}", new { controller = "Home", action = "ViewById"}, new{id = @"\d+"});

I see many answer about having string without space, but none of them works on MVC routing.

looking for a regex, gives me true on case of this:

"д_test.8_.は_any_language_without.Space"

and give me false on case of:

"a b"


Solution

  • I hope this is what you are looking for

    routes.MapRoute(
        name: "aaaaa",
        url: "{id}",
        defaults: new { controller = "pages", action = "view" },
        constraints: new { id = @"^[a-zA-Z0-9\w]*$" } //*********this should work**
    );