Closed IanMercer closed 11 years ago
That would be pretty cool. Is this something that should be independent of AR though, as a general routing util?
Actually all you would need is a model binder that splits a string by '/' or whatever character your want and then set your action parameter as
public ActionResult Icon([ModelBinder(typeof(SplitStringBinder))] IEnumerable<string> pathInfo) {
class StringStringModeBinder : IModelBinder
{
#region IModelBinder Members
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
if (bindingContext.ValueProvider.ContainsPrefix(bindingContext.ModelName))
{
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
if (value != null)
return value.AttemptedValue.Split('/');
}
return null;
}
#endregion
}
This is rough and untested but it should be in the right direction.
I came across this whilst migrating an existing application to AttributeRouting. There was an instance of {*pathinfo} in an existing route that I needed to migrate. It would be nice to have it in AttributeRouting to make migration easy. Admittedly the use in this case was more of an "abuse" (passing a list of items) so maybe I should just fix that!
Hi Ian, going to close this as I feel it's outside the scope of AR. Good luck with your implementation!
Would be nice if you could define a route like that and get an IEnumerable<string> pathInfo as the parameter.