2013-01-18 30 views
1

我有一個重載actionlink的函數,並且簡單地爲路由值「ID」添加一個新參數,我在這個地方使用了這個參數。在MVC和htmlAttributes中重載ActionLink

這是到目前爲止我的代碼:

public static MvcHtmlString ReportActionLink(this HtmlHelper helper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes) 
{ 
    RouteValueDictionary routeValueDictionary = new RouteValueDictionary(routeValues); 
    routeValueDictionary.Add("id", HttpContext.Current.Request.RequestContext.RouteData.Values["id"]); 

    IDictionary<string, object> attrs = new RouteValueDictionary(htmlAttributes); 

    return helper.ActionLink(linkText, actionName, controllerName, routeValueDictionary, attrs);   
} 

正如你所看到的,我通過在routeValues,並將其轉換爲一個字典,並添加我的ID。

,當我將我htmlAttributes並IDictionary的,因爲重載方法預計,它不會取代下劃線在我的特性,即

data_event =「東西」不會成爲數據事件發生的問題= 「某事」與匿名類型一樣。它用下劃線呈現。我想知道這是爲什麼,如果沒有辦法轉換它?

+0

您可以添加ReportActionLink的示例調用嗎? –

回答