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 4077974
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:37:02+00:00 2026-05-20T17:37:02+00:00

We have an a PHP application that we are converting to MVC. The goal

  • 0

We have an a PHP application that we are converting to MVC. The goal is to have the application remain identical in terms of URLs and HTML (SEO and the like + PHP site is still being worked on). We have a booking process made of 3 views and in the current PHP site, all these view post back to the same URL, sending a hidden field to differentiate which page/step in the booking process is being sent back (data between pages is stored in state as the query is built up).

To replicate this in MVC, we could have a single action method that all 3 pages post to, with a single binder that only populates a portion of the model depending on which page it was posted from, and the controller looks at the model and decides what stage is next in the booking process. Or if this is possible (and this is my question), set up a route that can read the POST parameters and based on the values of the POST parameters, route to a differen action method.

As far as i understand there is no support for this in MVC routing as it stands (but i would love to be wrong on this), so where would i need to look at extending MVC in order to support this? (i think multiple action methods is cleaner somehow).

Your help would be much appreciated.

  • 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-20T17:37:03+00:00Added an answer on May 20, 2026 at 5:37 pm

    I have come upon two solutions, one devised by someone I work with and then another more elegant solution by me!

    The first solution was to specify a class that extends MVcRouteHandler for the specified route. This route handler could examine the route in Form of the HttpContext, read the Form data and then update the RouteData in the RequestContext.

    MapRoute(routes, 
                "Book",
                "{locale}/book",
                new { controller = "Reservation", action = "Index" }).RouteHandler = new ReservationRouteHandler();
    

    The ReservationRouteHandler looks like this:

    public class ReservationRouteHandler: MvcRouteHandler
    {
        protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var request = requestContext.HttpContext.Request;
    
            // First attempt to match one of the posted tab types
            var action = ReservationNavigationHandler.GetActionFromPostData(request);
    
            requestContext.RouteData.Values["action"] = action.ActionName;
            requestContext.RouteData.Values["viewStage"] = action.ViewStage;
    
            return base.GetHttpHandler(requestContext);
        }        
    

    The NavigationHandler actually does the job of looking in the form data but you get the idea.

    This solution works, however, it feels a bit clunky and from looking at the controller class you would never know this was happening and wouldn’t realise why en-gb/book would point to different methods, not to mention that this doesn’t really feel that reusable.

    A better solution is to have overloaded methods on the controller i.e. they are all called book in this case and then define your own custome ActionMethodSelectorAttribute. This is what the HttpPost Attribute derives from.

     public class FormPostFilterAttribute : ActionMethodSelectorAttribute
    {
        private readonly string _elementId;
        private readonly string _requiredValue;
    
        public FormPostFilterAttribute(string elementId, string requiredValue)
       { 
            _elementId = elementId;
            _requiredValue = requiredValue;
        }
    
        public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
        {
            if (string.IsNullOrEmpty(controllerContext.HttpContext.Request.Form[_elementId]))
            {
                return false;
            }
    
            if (controllerContext.HttpContext.Request.Form[_elementId] != _requiredValue)
            {
                return false;
            }
    
            return true;
        }
    }
    

    MVC calls this class when it tries to resolve the correct action method on a controller given a URL. We then declare the action methods as follows:

    public ActionResult Book(HotelSummaryPostData hotelSummary)
        {
            return View("CustomerDetails");
        }
    
        [FormFieldFilter("stepID", "1")]
        public ActionResult Book(YourDetailsPostData yourDetails, RequestedViewPostData requestedView)
        {
            return View(requestedView.RequestedView);
        }
    
        [FormFieldFilter("stepID", "2")]
        public ActionResult Book(RoomDetailsPostData roomDetails, RequestedViewPostData requestedView)
        {
            return View(requestedView.RequestedView);
        }
    
        [HttpGet]
        public ActionResult Book()
        {
            return View();
        }
    

    We have to define the hidden field stepID on the different pages so that when the forms on these pages post back to the common URL the SelectorAttributes correctly determines which action method to invoke. I was suprised that it correctly selects an action method when an identically named method exists with not attribute set, but also glad.

    I haven’t looked into whether you can stack these method selectors, i imagine that you can though which would make this a pretty damn cool feature in MVC.

    I hope this answer is of some use to somebody other than me. 🙂

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

Sidebar

Related Questions

I have a PHP application that will on occasion have to handle URLs where
I have a php application that doesn't use the mvc model that i would
I have a PHP application that displays a list of options to a user.
I have a PHP application that makes extensive use of Javascript on the client
I have a PHP web application on an intranet that can extract the IP
I have a small AJAX application, written in PHP that I did not secure
I have inherited an old crusty PHP application , and I'd like to refactor
In a PHP application I am writing, I would like to have users enter
I have a PHP application that needs to generate some PDF invoices and PDF
I have an existing web application that I am converting to use CakePHP. The

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.