views:

282

answers:

1

I'm using jQuery to POST an Id to my route, for example:
http://localhost:1234/Load/Delete
with a POST Parameter Id = 1

I'm only using the default route in Global.asax.cs right now:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = "" }
);

When I perform the POST, in my ActionFilter filterContext.RouteData.Values["Id"] is set to the default value of "". Ideally, I'd like it to use the POST Parameter value automatically if the URL comes up with "". I know it is posting properly because I can see the value of "1" in filterContext.HttpContext.Request.Params["Id"].

Is there a way to get RouteData to use a POST parameter as a fall back value?

+1  A: 

You can always add another route that does not use this parameter. I have an example in my ASP.Net MVC book at home. I'll update this when I get home :)

But I would suggest renaming id to ObjectId for clarity, either in the route or in your jquery caller.

Couldn't find the reference, but from the looks of it your best bet is to change the name of the id in the entity. Most ASP.Net MVC articles suggest using ConferenceId, PersonId, etc.

HeavyWave
So I tried changing the POST parameter to LoadId = 1, but the value still appears in my Request.Form["LoadId"] and not in RouteData.Values["LoadId"]. Is there a way to get it into RouteData when it is a POSTed value?
DavGarcia
Why would it be in your RouteData, if it's not in the URL (i.e. route)? It should be a parameter of your controller's action when it's a POST value.
HeavyWave