Editor
Dec 7, 2012 at 2:46 AM
Edited Dec 7, 2012 at 2:47 AM
|
If I have a controller action like this:
public ActionResult MyAction(Guid myParam)
In javasript, I can do this:
var someUrl=@Url.Action(MVC.MyController.MyAction())
That will generate "/MyController/MyAction'....and that is perfect.
Now, if you decide to do some sort of client side binding where the parameter is bound from a datasource you can use
someUrl+"?myParam="+theparam;
All good....now for the issue. As you can see, the Guid parameter is required for this method. So, if I change the route for this action to contain a Guid constraint on the myParam parameter, T4MVC will no longer find the route! This make
sense because it passes the area, controller and action to the Routing engine and there is not a match. How would you propose we could fix that?
One thing I thought of was our own Url extension method - something like Url.ActionRoot(MVC.MyController.MyAction()) where it is NOT sent to MVC routing engine for outbound url generation, but rather just creates /{area}/{controller/{action} url and returns
it? Basically we are in a situation where we do want to restrict what is required from a routing point of view - but we also need to be able to build that route string dynamically without any magic strings.
Without something like the above, we would have to resort to something like this in javascript:
var someUrl="/"+MVC.MyController.Name+"/"MVC.MyController.MyAction.Name
Davide - any thoughts? (BTW, really liked the change to having the common classes for T4MVC in their own NuGet dll - made it where I could extend it 'normally' rather than putting code in the hooks class.)
|