MVC - Personalize the POST Form

I created an MVC application that dynamically routes actions and controllers based on user data, so there are no standard actions, but dynamically named actions.

In order to properly control the controller and action, each route must go through a centralized Index, which determines whether the user has switched to a valid System in this case. i.e.

http://mysite.com/Systems/SystemName/RenameSystem 

... where SystemName is the name of the dynamic system and RenameSystem is the action.

Once the system has been correctly configured for the RenameSystem controller, the user is prompted with a text field that allows them to change the name of the system. When the submit button is clicked, the form is redirected back to my original index controller

public ActionResult Index(string systemName, string action)

instead of the standard

public ActionResult RenameSystem(string systemName)

I put the logic to determine if RequestType is POST or GET. If RequestType is a POST, the logic is rejected and may capture form data contained in the request object.

My question is: how can I take form data that contains my systemName field and route it so that I don’t need to throw data into the switch statement. that is, I DO NOT want to do this:

switch case(action)
{  
      case "RenameSystem":
      return RenameSystem(Request.Form["systemName"]);
}

and that I can dynamically POST with the standard:

public ActionResult RenameSystem(string systemName)

... just personifying the defiant look.

Simply put, I would like to take the RenameSystem action and call it so that my system name automatically falls into the systemName parameter in RenameSystem.

Is this possible or are there other options for how to do this?

Thanks George

+3
source share
1

ControllerActionInvoker InvokeAction ControllerContext.

+3

Source: https://habr.com/ru/post/1726739/


All Articles