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

  • Home
  • SEARCH
  • 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 3850176
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:58:08+00:00 2026-05-19T16:58:08+00:00

I have an Asp.net MVC app that currently works well using the default model

  • 0

I have an Asp.net MVC app that currently works well using the default model binder and urls with complex parameters like this:

example.com/Controller/Action?a=hello&b=world&c=1&d=2&e=3 (notice the question mark)

The different urls automatically map to Action Method parameters using the built in model binder. I would like to continue using the standard model binder but I need to get rid of the query string. We want to put these urls behind a CDN that does not support resources that vary by query strings (Amazon Cloud front) so we need to remove the question mark from our urls and do something silly like this

example.com/Controller/Action/a=hello&b=world&c=1&d=2&e=3 (no question mark)

These urls are only used via AJAX, so I’m not interested in making them user or SEO friendly. I want to just drop the question mark and keep all my code exactly the same. The hitch is, I’m unsure about how to keep using the MVC model binder and abandoning it would be a lot of work.

I don’t want to use a complex route to map my objects like this question did and, instead, I am planning to use a single simple route like the one below

   routes.MapRoute(
        "NoQueryString",                    // Route name
        "NoQueryString/{action}/{query}", // 'query' = querystring without the ?
        new {
            controller = "NoQueryString",
            action = "Index",
            query = "" }  // want to parse with model binder - By NOT ROUTE
    );

Option 1 (preferred): OnActionExecuting
I plan to use the catchall “query” value in the route above to inject the old query string into the default model binder before the Controller Actions execute using the OnActionExecuting method in my controller. However, I’m a bit unsure if I can just add back the question mark. Can I do this? How would you recommend modifying the url?

Option 2: Custom Model Binder
I also could make some sort of Custom Model Binder that just tells the default model binder to treat the “query” value like a query string. Would you prefer this method? Can you point me to a relevant example?

I am a bit worried that this is an edge case and would love some input before I start trying to implement Option 1 or Option 2 and stumble onto unforseen bugs.

  • 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-19T16:58:09+00:00Added an answer on May 19, 2026 at 4:58 pm

    You could use a custom value provider with a catchall route:

    routes.MapRoute(
        "NoQueryString",
        "NoQueryString/{controller}/{action}/{*catch-em-all}",
        new { controller = "Home", action = "Index" }
    );
    

    and the value provider:

    public class MyCustomProvider : ValueProviderFactory
    {
        public override IValueProvider GetValueProvider(ControllerContext controllerContext)
        {
            var value = controllerContext.RouteData.Values["catch-em-all"] as string;
            var backingStore = new Dictionary<string, object>();
            if (!string.IsNullOrEmpty(value))
            {
                var nvc = HttpUtility.ParseQueryString(value);
                foreach (string key in nvc)
                {
                    backingStore.Add(key, nvc[key]);
                }
            }
            return new DictionaryValueProvider<object>(
                backingStore, 
                CultureInfo.CurrentCulture
            );
        }
    }
    

    which you register in Application_Start:

    ValueProviderFactories.Factories.Add(new MyCustomProvider());
    

    and now all that’s left is a model:

    public class MyViewModel
    {
        public string A { get; set; }
        public string B { get; set; }
        public string C { get; set; }
        public string D { get; set; }
        public string E { get; set; }
    }
    

    and a controller:

    public class HomeController : Controller
    {
        [ValidateInput(false)]
        public ActionResult Index(MyViewModel model)
        {
            return View(model);
        }
    }
    

    and then navigate to: NoQueryString/Home/Index/a=hello&b=world&c=1&d=2&e=3. The Index is hit and the model is bound.

    Remark: Notice the ValidateInput(false) on the controller action. That’s probably gonna be needed because ASP.NET won’t allow you to use special characters such as & as part of a URI. You might also need to tweak your web.config a little:

    <httpRuntime requestValidationMode="2.0" requestPathInvalidCharacters=""/>
    

    For more information about those tweaks make sure you have read Scott Hansleman’s blog post.

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

Sidebar

Related Questions

Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
I have an asp.net mvc app running on a local iis website that is
I have an ASP.NET MVC (Beta 1) website that I'm using themes with. When
I have an interesting situation where I need to deploy an ASP.NET MVC app
I am building my first ASP.Net MVC based app and have a problem accessing
Background I have a page on my ASP.NET MVC web app for users to
I have a mixed UI (Win App, WPF App, and soon an ASP.NET MVC
I have an ASP.NET MVC-application which I want deployable on both IIS6 and IIS7
I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
I have an ASP.NET MVC application, when a user clicks on the submit button

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.