Ado Ado - 1 year ago 76
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()

Answer Source

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>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download