2011-05-27 56 views
2

我目前在看這個:BuildUrlFromExpression

Radchart in ASP.NET MVC

,但不知道如何處理這段代碼:

string url = helper.BuildUrlFromExpression<T>(action); 

這是一個MVC輔助方法,我可以使用?任何反饋將非常感激。謝謝!

基督教

回答

5

我有更好的回答。

public static string Image<T>(this HtmlHelper helper, Expression<Action<T>> action, int width, int height, string alt) 
      where T : Controller 
    { 
     var expression = action.Body as MethodCallExpression; 
     string actionMethodName = string.Empty; 
     if (expression != null) 
     { 
      actionMethodName = expression.Method.Name; 
     } 
     string url = new UrlHelper(helper.ViewContext.RequestContext, helper.RouteCollection).Action(actionMethodName, typeof(T).Name.Remove(typeof(T).Name.IndexOf("Controller"))).ToString();   
     //string url = LinkBuilder.BuildUrlFromExpression<T>(helper.ViewContext.RequestContext, helper.RouteCollection, action); 
     return string.Format("<img src=\"{0}\" width=\"{1}\" height=\"{2}\" alt=\"{3}\" />", url, width, height, alt); 
    } 
} 
0

該做的工作:

string url = Microsoft.Web.Mvc.LinkBuilder.BuildUrlFromExpression<T>(helper.ViewContext.RequestContext, helper.RouteCollection, action);