Search code examples
asp.net.netasp.net-mvcurimailto

How to invoke mailto link on clients side in controller's Action in MVC 5.1?


I would like to run link mailto:[email protected] on client's side inside controller's action.

How to perform this behaviour? As far as I know I have to run Java Script on their side to perform this.

Users of the site will be small group of IT students so if something has to be done on theirs side first I can manage that.


Solution

  • If your question is how can you activate this type of link automatically, via jQuery (which comes with ASP.NET MVC by default), it's easy:

    $('#myEmailLink').click();
    

    Obviously, you would either need to add an id to your link or change the selector to pick it out some other way.

    If you need to go pure JavaScript, it's a bit more complicated, but there's a nice solution on this StackOverflow question.