I have the following in my MVC View:
<a href='@Url.Action("EmailPerson", "SupportNeeded")'> Email </a>
Below, SupportNeeded is the Controller and EmailPerson in the method
What is the equivalent if I do it in Jquery. Obviously I do not need the Email Lable. I just want it to automatically go to EmailPerson Method in SupportNeeded controller.
Note that I have EmailPerson and EmailPerson with HttpPost in my controller.
I tried in my Jquery
'@Url.Action("EmailPerson", "SupportNeeded")'
but that didn't do anything for me. I also tried the .post :
var url = '@Url.Action("EmailPerson", "SupportNeeded")';
$.post(url), function (data) { });
but it went to the Method that has [HttpPost]. I need it to go to the method that does not have [HttpPost]. I then tried .get but did not do anything for me.
您应该能够通过使用常规JavaScript来完成此任务。
window.location = '@Url.Action("EmailPerson", "SupportNeeded")';
It's unclear what exactly you need. If you want to use $.get
which will perform an ajax request, this works:
$.get("@Url.Action("EmailPerson", "SupportNeeded")");
If you're trying to redirect to that action you can do:
window.location.href = "@Url.Action("EmailPerson", "SupportNeeded")";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.