I have a requirment to invoke a controller method from the view page. On click of the link below the method should be invoked.
@Html.ActionLink(item.InvoiceN
First of all
TARGET = "_blank"
Is used to open hyperreferenced resource in a new browser window, so if you don't want the new window - why would you put that in place ? :-)
Second, look at the ActionLink helper method (description I took from question referenced bellow):
Html.ActionLink(article.Title,
"Item", // <-- ActionMethod
"Login", // <-- Controller Name.
new { article.ArticleID }, // <-- Route arguments.
null // <-- htmlArguments .. which are none. You need this value
// otherwise you call the WRONG method ...
// (refer to comments, below).
)
take a look at HTML.ActionLink method
I assume you're hitting the wrong method overload if you get errors. If you replace htmlArguments with null, you should be good to go, but as your method returns VOID (nothing) you will get an empty page (what else would you expect :) ? )
To cancel the default navigation mechanism you can implement simple jquery rule :
$('a.invoicelinkclass').click(function(e){
e.preventDefault();
$.get($(this).attr('href'),function(){
// maybe an alert() or jquery ui .dialog() to let user know that something happened ?
});
});