Ado Ado - 10 months ago 36
HTML Question

Call a C# method from an html a tag

I have the following C# method, how can I call it from an HTML a tag?

<a href="#" runat="server" onclick="MyFunction()">CLICK</a>
public void MyFunction()


You can use jQuery ajax to MVC action:

function CallMyCShartAtion(id)
      url: 'urlToController', //path to the contoller's action
      data: { id: id }
   }).done(function() {

And then

<a href="#" runat="server" onclick="CallMyCShartAtion(5)">CLICK</a>