使用Ajax.ActionLink调用Action不起作用

时间:2016-01-26 17:15:40

标签: asp.net-mvc razor-3

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

if (company == null || company.getGroup() == null 
    || company.getGroup().getPerson() == null 
    || company.getGroup().getPerson().length() == 0 )
{
    return false;
}

return true;

但我明白了:

@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"
    })

在渲染的Html中。

我正在从另一个控制器调用print <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> 动作,但我总是得到路径中的当前控制器,不知道吗?

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

CustomerOrder

1 个答案:

答案 0 :(得分: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