0

I need to add a dynamic routevalue in html.beginform, something like this

Html.BeginForm("action", "controller", new { 

   somethingID = "some js function or jquery that get the value from a textbox" 

}))

I know mvc is already passing the paramenter to my method when the form submit, but I need the url to include the parameter in the mvc url format, ie mydomain.com/controller/action/somethingID. Eveything is working right now, but because I have another $.ajax() call that pass in the url, something like "../someMethod", the $.ajax() dont work because the current url is (mydomain.com/controller/action) not (mydomain.com/controller/action/somethingID).

Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
satuday
  • 165
  • 1
  • 1
  • 8

1 Answers1

0

Make sure to set as UrlParameter.Optional the id in your RouteConfig:

routes.MapRoute(
       name: "Default",
       url: "{controller}/{action}/{id}",
       defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional}
);
I.G. Pascual
  • 5,818
  • 5
  • 42
  • 58