MVC 5 doesn't seem to like JavaScript that much. I am creating link in JavaScript to a success method in my Ajax call.
Razor:
@Html.ActionLink("Amount", "Action", "Controller", new { id1 = "a", id2 ="b"}, new { target = "_blank"})
JavaScript:
$('#element').html('<a href="' + '@Url.Action("Action", "Controller", new { id1= "a", id2= "__id2__" })'.replace("__id2__", id2) + '" target="_blank">' + data[1] + '</a>');
This link works, but, I am not sure it's the best solution. Tried with a onclick
method on the element instead, and with a separate method for handling the link, but still doesn't really get around this replacing.
And if it has more parameters should I just be chaining them?
.replace("__id2__", id2).replace("__id3__", id3).replace("__id4__", id4) etc