I understand why routes exist and how having a very hard-coded set of routes can be useful.
But, I keep finding myself in these kinds of situations:
public PartialViewResult GetAssetHistory(string assetCode, string mode)
public PartialViewResult GetAssetData(string assetCode)
public PartialViewResult GetAssetData2(string assetCode, string mode, int assetParam)
I do not want to have to hard-code a route of
Asset/{action}/{assetCode}/{mode}/{assetParam}
It would be much better if I could just have all routes, or all controllers with an attribute set to dynamically create routes such that the first route value maps to the first parameter (e.g. assetCode) and the second route value maps to the second parameter of the action (e.g. mode), and so on?
I understand this would probably require reflection, but is there any reason why doing this could be very bad, or should not be done, or can't be done?
Bonus points for an example of doing this in the RouteConfig.cs
Aucun commentaire:
Enregistrer un commentaire