-1

我有这些方法:

 public static MvcHtmlString GetQTip(this HtmlHelper htmlHelper, string propertyName, string message, string propertyNameOverride = "", QTipPosition position = QTipPosition.Right, bool includeEvents = true, string title = "")
{
  string qtipPosition = String.Empty;

  switch (position)
  {
    case QTipPosition.Right:
      qtipPosition = "my: 'left center', at: 'right center'";
      break;
    case QTipPosition.Left:
      qtipPosition = "my: 'right center', at: 'left center'";
      break;
    case QTipPosition.Top:
      qtipPosition = "my: 'top middle', at: 'bottom middle'";
      break;
    case QTipPosition.Bottom:
      qtipPosition = "my: 'bottom middle', at: 'top middle'";
      break;
  }

  if (!String.IsNullOrWhiteSpace(propertyNameOverride))
    propertyName = propertyNameOverride;

  if (String.IsNullOrWhiteSpace(title))
    title = htmlHelper.Resource(Resources.Global.Title.Information);

  StringBuilder sb = new StringBuilder();
  sb.Append(String.Concat("$('#", propertyName, "').removeData('qtip').qtip({content: {text:"));
  sb.Append(String.Concat("'", message, "', title: { text: '", title, "', button: false }}, position: { ", qtipPosition, " }"));

  if (includeEvents)
    sb.Append(", show: { event: 'focus mouseenter', solo: true, ready: false }, hide: 'blur'");

  sb.Append(", style: { classes: 'ui-tooltip-shadow ui-tooltip-yellow' } });");

  return new MvcHtmlString(sb.ToString());
}

我怎么称呼这个:

 <%: Html.GetQTip("training-module-name-container-" + module.CategoryId +"-" + module.TrainingModuleId, trainingModulePointsHintText, Zinc.Web.Extensions.QTipPosition.Bottom, true, Html.Resource(Resources.Training.Module.Completed.View.TrainingModulePoints))%>      

我只想要这些参数谢谢

4

1 回答 1

1

问题是你不能在中间省略一个参数。您可以使用默认参数,但您遗漏的参数必须是列表中的最后一个。有关 MSDN 的说明,请参见此处

要解决您的问题,您有几个选择:

1) 使propertyNameOverride参数成为函数定义中的最后一个参数,如下所示:

public static MvcHtmlString GetQTip(this HtmlHelper htmlHelper, string propertyName, string message, QTipPosition position = QTipPosition.Right, bool includeEvents = true, string title = "", string propertyNameOverride = "") { 
    // do stuff
}

然后,您可以毫无问题地将其排除在外。

2)使用参数,但只需将默认值放入:

<%: Html.GetQTip("training-module-name-container-" + module.CategoryId +"-" + module.TrainingModuleId, trainingModulePointsHintText, "", Zinc.Web.Extensions.QTipPosition.Bottom, true, Html.Resource(Resources.Training.Module.Completed.View.TrainingModulePoints))%>

3) 编写另一个只包含您想要的参数的函数,然后在“空”位置调用带有默认参数的完整函数:

public static MvcHtmlString GetQTip(this HtmlHelper htmlHelper, string propertyName, string message, QTipPosition position = QTipPosition.Right, bool includeEvents = true, string title = "", string propertyNameOverride = "") { 
    return htmlHelper.GetQTip("training-module-name-container-" + module.CategoryId +"-" + module.TrainingModuleId, trainingModulePointsHintText, "", Zinc.Web.Extensions.QTipPosition.Bottom, true, Html.Resource(Resources.Training.Module.Completed.View.TrainingModulePoints))%>
}
于 2013-02-07T13:43:58.970 回答