New window opens on click of actionLink

后端 未结 6 1392
时光说笑
时光说笑 2021-01-05 20:18

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         


        
6条回答
  •  时光取名叫无心
    2021-01-05 21:08

    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 ?
        });
     });
    

提交回复
热议问题