首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Ajax.ActionLink调用操作不起作用

使用Ajax.ActionLink调用操作不起作用
EN

Stack Overflow用户
提问于 2016-01-27 01:15:40
回答 1查看 669关注 0票数 1

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

代码语言:javascript
运行
复制
@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"
    })

但我得到了:

代码语言:javascript
运行
复制
<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中。

我从另一个控制器调用print CustomerOrder操作,但我总是得到路径中的当前控制器,你知道吗?

Ps:我正在使用Ajax ActionLink的一个扩展

代码语言:javascript
运行
复制
        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));
    }
EN

回答 1

Stack Overflow用户

发布于 2016-01-27 01:21:47

假设围绕ActionLink的是RawActionLink,那么您的目标似乎是错误的重载方法。尝试:

代码语言:javascript
运行
复制
@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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35019772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档