+ is a reserved character in the URL. This means a space. Thus, in order to achieve what you are looking for, you can write your own connecting device:
public class StringModelBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); if (value != null && !string.IsNullOrEmpty(value.AttemptedValue)) { return value.AttemptedValue.Split(' '); } return base.BindModel(controllerContext, bindingContext); } }
and then either register it globally for type string[] , or use the ModelBinder attribute:
public ActionResult MyActionName( [ModelBinder(typeof(StringModelBinder))] string[] ids ) { return View(ids); }
Obviously, if you want to use the URL of the form /MyControllerName/MyActionName/Id1+Id2+Id3+Id4 , which will bind the last part as an action parameter with the name ids , you will have to change the default route definition using {id} .
source share