As everyone has noted, the easiest fix would be not to use a dash. If you truly need the dash, you can create your own ActionFilterAttribute to handle it, though.
Something like:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class ParameterNameAttribute : ActionFilterAttribute
{
public string ViewParameterName { get; set; }
public string ActionParameterName { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if(filterContext.ActionParameters.ContainsKey(ViewParameterName))
{
var parameterValue = filterContext.ActionParameters[ViewParameterName];
filterContext.ActionParameters.Add(ActionParameterName, parameterValue);
}
}
}
You would then apply the filter to the appropriate Action method:
[ParameterName( ViewParameterName = "user-data", ActionParameterName = "userData")]
[ParameterName( ViewParameterName = "my-data", ActionParameterName = "myData" )]
public ActionResult About(string userData, string myData)
{
return View();
}
You would probably want to enhance the ParameterNameAttribute to handle upper/lower case, but that would be the basic idea.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…