Sweet merciful Chaos, what did I just write?

  • SockDev

    The odd syntax is because this is JavaScript with some lovely C#/Razor thrown in.

    So I had to write this:

    var dispensationsAction = '@Url.Action("DispensationsAjax", "PayrollGroup", new { payrollGroupId = @Model.Id, readOnly = @Model.HasActivePayrollBatch }, null)';
    //It's a hack, but it's required, otherwise the readOnly flag isn't passed correctly
    dispensationsAction = dispensationsAction.replace('&', '&');

    Why? Well, Url.Action auto-escapes ampersands when creating the URL. While this is fine for <a> tags, it doesn't work then JavaScripting your AJAX.

    I don't like writing code that makes my quills twitch; is there another way?

    <!-- Emoji'd by MobileEmoji 0.2.0-->

  • @RaceProUK said:

    is there another way?

    Can you show where dispensationsAction is actually used....it would be helpful in possibly locating alternatives...

  • SockDev

    It goes into a JS method that adds a few more items to the query string, then invokes $.ajax().

    Really, the issue lies with Url.Action().

    <!-- Emoji'd by MobileEmoji 0.2.0-->

  • wrap it in @Html.Raw()


    var dispensationsAction = '@Html.Raw(Url.Action("DispensationsAjax", "PayrollGroup", new { payrollGroupId = @Model.Id, readOnly = @Model.HasActivePayrollBatch }, null))';

  • SockDev


    <!-- Emoji'd by MobileEmoji 0.2.0-->

Log in to reply

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.