WorknHardr
asked on
MVC Action Params Null?
I've read other posts and still doing something wrong, params always null. Help!
- view -
@Html.ActionLink("Make a new file...", "MakeFile", "FileMaker", new { id = "pdf", type = "sales" })
- action -
public ActionResult MakeFile(string id, string type) // both strings null
{
}
- global.asax -
routes.MapRoute(
"12",
"FileMaker/MakeFile/{id, type}", new { controller = "FileMaker", action = "MakeFile", id = "", type = "" }
)
ASKER
Error:
The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.
Parameter name: routeUrl
The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.
Parameter name: routeUrl
It looks to me like the default MVC route mapping would work fine. Why are you defining a route? Routing does not use the query string this way. But the default binding will handle it without problems.
Try removing that routing definition from global.asax. Put some code in your MakeFile method and click your action link.
Try removing that routing definition from global.asax. Put some code in your MakeFile method and click your action link.
ASKER
Solution:
1. Removed global.asax maproute for this actionlink
2. Added a 5th actionlink param (null)
3. Now it works.
4. I think MVC routing is screwy
@Html.ActionLink("Make a new file...",
"MakeFile", "FileMaker", new { id = "pdf", type = "sales" }, null)
1. Removed global.asax maproute for this actionlink
2. Added a 5th actionlink param (null)
3. Now it works.
4. I think MVC routing is screwy
@Html.ActionLink("Make a new file...",
"MakeFile", "FileMaker", new { id = "pdf", type = "sales" }, null)
The last parameter, which should be an object containing HTML attributes that get added to the link, should not really be needed either, especially as you are just passing null. What URL is generated in the link with and without it?
ASKER
I don't get it either, MVC 3 routing is screwy
Without the 5th param (null) the url ends with ?Length=10
Without the 5th param (null) the url ends with ?Length=10
Interesting, because it looks like it is automatically adding what should be an HTML attribute.
If you right click the ActionLink statement and select "Go to definition" does it show a definition in System.Web or has someone overridden it with a custom definition in the project.
If you right click the ActionLink statement and select "Go to definition" does it show a definition in System.Web or has someone overridden it with a custom definition in the project.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
thx for helping my figure this out...
Solution: (5th param = ,NULL
@Html.ActionLink("Make a new file...",
"MakeFile", "FileMaker", new { id = "pdf", type = "sales" }, null)
Solution: (5th param = ,NULL
@Html.ActionLink("Make a new file...",
"MakeFile", "FileMaker", new { id = "pdf", type = "sales" }, null)
No problem. Some of those overloads are tricky with string, string, string, object etc, and because of the object parameters, they can accept anything. I should have checked that first.
Open in new window