1

I have a really weirdo issue, I write :

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

but I get :

<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>

in the rendered Html.

I'm calling the print CustomerOrder action from another controller but I get always the current controller in the path, any idea ?

Ps: I'm using an extension of 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));
    }
BeSome
  • 15
  • 5
  • Is [this](http://timjames.me/mvc-actionlink-with-html-content/) where you're getting `RawActionLink` from? – Richard Ev Jan 26 '16 at 17:21
  • I got it from msdn, yes it's same – BeSome Jan 26 '16 at 17:27
  • There's an extension on SO [here](http://stackoverflow.com/a/16983575/2030565). – Jasen Jan 26 '16 at 17:28
  • You should include the extension definition in your question so it is clear to everyone how you implemented `RawActionLink`. – Jasen Jan 26 '16 at 17:32
  • I think it's a routing problem, the wrong appears in the line where we call ajaxHelper.ActionLink – BeSome Jan 26 '16 at 17:41
  • Use Intellisense to help you. Hover over `ajaxHelper.ActionLink(...)` -- What overload is it showing? You can help yourself by using named arguments `.ActionLink(linkText: repID, actionName: actionName, ...)` you'll notice parameters don't line up. – Jasen Jan 26 '16 at 17:51
  • I wasn't passing the routeValues parameter in the call of Ajax ActionLink. Thank you all for your pressure help. – BeSome Jan 26 '16 at 18:14

1 Answers1

1

Assuming that RawActionLink is wrapped around ActionLink it seems that you are targeting wrong overloaded method. Try:

@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

serhiyb
  • 4,753
  • 2
  • 15
  • 24