[英]MVC Call Controller/Method from Jquery
I have the following in my MVC View: 我的MVC视图中具有以下内容:
<a href='@Url.Action("EmailPerson", "SupportNeeded")'> Email </a>
Below, SupportNeeded is the Controller and EmailPerson in the method 下面,SupportNeeded是方法中的Controller和EmailPerson
What is the equivalent if I do it in Jquery. 如果我在Jquery中进行操作,这是等效的。 Obviously I do not need the Email Lable.
显然,我不需要电子邮件标签。 I just want it to automatically go to EmailPerson Method in SupportNeeded controller.
我只希望它自动转到SupportNeeded控制器中的EmailPerson方法。
Note that I have EmailPerson and EmailPerson with HttpPost in my controller. 请注意,我的控制器中有带有HttpPost的EmailPerson和EmailPerson。
I tried in my Jquery 我在Jquery中尝试过
'@Url.Action("EmailPerson", "SupportNeeded")'
but that didn't do anything for me. 但这对我没有任何帮助。 I also tried the .post :
我也尝试了.post:
var url = '@Url.Action("EmailPerson", "SupportNeeded")';
$.post(url), function (data) { });
but it went to the Method that has [HttpPost]. 但它转到具有[HttpPost]的Method。 I need it to go to the method that does not have [HttpPost].
我需要它去没有[HttpPost]的方法。 I then tried .get but did not do anything for me.
然后,我尝试使用.get,但没有为我做任何事情。
您应该能够通过使用常规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
来执行ajax请求,则可以这样做:
$.get("@Url.Action("EmailPerson", "SupportNeeded")");
If you're trying to redirect to that action you can do: 如果您尝试重定向到该操作,则可以执行以下操作:
window.location.href = "@Url.Action("EmailPerson", "SupportNeeded")";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.