Click here to Skip to main content
14,430,403 members
Rate this:
Please Sign up or sign in to vote.
See more:
How to call a controller action in anchor tag.

I have tried this these code, but not working

<a href="/BPGController/AddToContact">Add to Contact</a><br />
<a href="@Url.Action("AddToContact", "BPGController")">Add to Contact</a><br />
<a href="#" onclick="location.href='@Url.Action("AddToContact")'">Add to Contact</a><br />
@Html.ActionLink("Add to Contact", "AddToContact", "BPGController")

None of them working. I am beginner in MVC.
Posted
Updated 25-Nov-19 9:31am
Rate this:
Please Sign up or sign in to vote.

Solution 1

In your 2nd try, Use BPG in place of BPGController.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

<a href="<?php echo base_url('BPGController/AddToContact')?>"></a>
   
v2
Comments
OriginalGriff 11-Nov-19 2:41am
   
While I applaud your urge to help people, it's a good idea to stick to new questions, rather than 5 year old ones. After that amount of time, it's unlikely that the original poster is at all interested in the problem any more! And you have to be careful as well - your solution appeared to be blank because you didn't enclose it in pre tags (use the code> widget when entering it) so it looks even more like abusive behaviour.
Answering old questions can be seen as rep-point hunting, which is a form of site abuse. The more trigger happy amongst us will start the process of banning you from the site if you aren't careful. Stick to new questions and you'll be fine.

I've edited it so it now appears less like abuse, and I'll get the banning procedure stopped - but please, be more careful next time!
Richard Deeming 11-Nov-19 4:26am
   
In addition to Griff's comments, the original question appears to be about ASP.NET MVC; your solution is for PHP.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100