1

我有一个非常奇怪的问题,我写道:

@Ajax.RawActionLink(
    "<i class=\"fa fa-print\"></i>",
    "CustomerOrder",
    "PrintSheet",
    new AjaxOptions()
    {
        UpdateTargetId = "bodyContent",
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "GET"
    },
    new
    {
        @class = "btn btn-success",
        data_toggle = "tooltip",
        data_placement = "top",
        title = "Imprimer"
    })

但我得到:

<a class="btn btn-success"
  data-ajax="true"
  data-ajax-method="GET"
  data-ajax-mode="replace"
  data-ajax-update="#bodyContent"
  data-placement="top"
  data-toggle="tooltip"
  href="/Sales/CustomerOrder?Length=10"
  title=""
  data-original-title="Imprimer">
    <i class="fa fa-print"></i>
</a>

在呈现的 HTML 中。

我正在CustomerOrder从另一个控制器调用打印操作,但我总是在路径中获得当前控制器,知道吗?

ps:我用的是Ajax ActionLink的扩展

        public static MvcHtmlString RawActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, AjaxOptions ajaxOptions, object htmlAttributes)
    {
        var repID = Guid.NewGuid().ToString();
        var lnk = ajaxHelper.ActionLink(repID, actionName, controllerName, ajaxOptions, htmlAttributes);
        return MvcHtmlString.Create(lnk.ToString().Replace(repID, linkText));
    }
4

1 回答 1

1

假设 RawActionLink 包裹在 ActionLink 周围,似乎您的目标是错误的重载方法。尝试:

@Ajax.RawActionLink(
    "<i class=\"fa fa-print\"></i>", //content
    "CustomerOrder", //action
    "PrintSheet", //controller
    new {}, //routing data <---- ADDED
    new AjaxOptions() //ajax options
    {
        UpdateTargetId = "bodyContent",
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "GET"
    },
    new //html attributes
    {
        @class = "btn btn-success",
        data_toggle = "tooltip",
        data_placement = "top",
        title = "Imprimer"
    })

https://msdn.microsoft.com/en-us/library/system.web.mvc.ajax.ajaxextensions.actionlink(v=vs.118).aspx#M:System.Web.Mvc.Ajax.AjaxExtensions.ActionLink %28System.Web.Mvc.AjaxHelper,System.String,System.String,System.String,System.Object,System.Web.Mvc.Ajax.AjaxOptions,System.Object%29

于 2016-01-26T17:21:47.010 回答