Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6595467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:56:38+00:00 2026-05-25T17:56:38+00:00

I am trying to create a route constraint but not sure what would be

  • 0

I am trying to create a route constraint but not sure what would be the best for this. Here is the route with no constraint :

context.MapRoute(
    "Accommodation_accomm_tags",
    "accomm/{controller}/{action}/{tag}",
    new { action = "Tags", controller = "AccommProperty" },
    new { tag = @"" } //Here I would like to put a RegEx for not null match
);

What would be the best solution for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:56:38+00:00Added an answer on May 25, 2026 at 5:56 pm

    Why do you need a constraint for a not null/empty match? Normally if you define your route like this:

    context.MapRoute(
        "Accommodation_accomm_tags",
        "accomm/{controller}/{action}/{tag}",
        new { action = "Tags", controller = "AccommProperty" },
    );
    

    and tag is not specified in the request url this route simply won’t match.

    And if you want a token to be optional, then:

    context.MapRoute(
        "Accommodation_accomm_tags",
        "accomm/{controller}/{action}/{tag}",
        new { action = "Tags", controller = "AccommProperty", tag = UrlParameter.Optional },
    );
    

    Constraints are used when you want to constrain the value of a given route token to some specific format.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a route with a Username... So the URL would
I'm trying to create a route that looks like this site.com/controller/{Param1}/{dbID}-{friendly-name} and omit the
I'm trying to create an ASP.NET MVC2 route with a regular expression constraint to
Ok so I am trying create a login script, here I am using PHP5
Trying to create a user account in a test. But getting a Object reference
Trying to create my first iPhone app that would play back audio. When I
I'm a bit rusty with Rails. I'm trying to create a route that should
I'm trying to create a custom route like: search/result/city/p1/state/p2/zip/p3/min/p4/max/p5/bed/p6/bath/p7/cats/p8/dogs/p9/parking/p10 Where search is the controller
I'm trying to create the above mentioned route... year, month, day and title should
I am trying to create a form in my view that will route to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.