I have a controller action that takes an id as a parameter. The restful way to call this is: /Controller/Action/id, and if I use an ActionLink helper (below), the URL is generated correctly.
Html.ActionLink(linkText, action, controller, new { id = myid })
However, I need to get the url to open the page in a new window. I tried using BuildUrlFromExpressionForAreas, but it gives me a url in the following format: /Controller/Action?id=myid.
Html.BuildUrlFromExpressionForAreas<MyController>(t => t.Action(myid))
This doesn't work - I get the following exception:
The parameters dictionary contains a null entry for parame开发者_JAVA技巧ter 'id' of non-nullable type 'System.Guid' for method 'System.Web.Mvc.ActionResult Resume(System.Guid)'
Is there another helper method I should use?
Thanks!
Hopefully, there's a better approach, but in the mean time, here's my solution:
1 - Add "action-link" class to action links
Html.ActionLink(linkText, action, controller, new { id = myid }, new { @class='action-link'})
2 - Use jquery to get the generated url and bind it to the click event and set href to #
$(document).ready(function () {
$(".action-link").each(
function (index, el) {
var url = $(this).attr("href");
$(this).attr("href", "#").bind("click",
function () {
var options = "resizable=yes,scrollbars=yes,toolbar=no,status=no,menubar=no";
window.open(url, "Interview", options, true);
});
}
);
});
精彩评论