admin管理员组文章数量:1356142
So I am calling my action result method using this:
var url= "/Example/Controler/1/Action";
$("<form action='"+url+"'></form>").submit();
But the action Method is not called... I have also tried this
$.post(url, function (data) {});
And this works, we call the controller, but then the page doesn't refresh...
My action method looks like this:
public ActionResult DoStuff(int Id)
{
.....
return RedirectToAction("index", new { Id });
}
So I am calling my action result method using this:
var url= "/Example/Controler/1/Action";
$("<form action='"+url+"'></form>").submit();
But the action Method is not called... I have also tried this
$.post(url, function (data) {});
And this works, we call the controller, but then the page doesn't refresh...
My action method looks like this:
public ActionResult DoStuff(int Id)
{
.....
return RedirectToAction("index", new { Id });
}
Share
Improve this question
edited Mar 25, 2014 at 14:48
Greeed
asked Mar 25, 2014 at 12:55
GreeedGreeed
4192 gold badges8 silver badges29 bronze badges
3
-
Are you actually submitting data? (is the
<form>
required?) Also, is your action decorated withHttpPost
by chance? – Brad Christie Commented Mar 25, 2014 at 12:57 - In $.post() method success function, you have to update page content – 111 Commented Mar 25, 2014 at 12:58
- @ Brad Christie nope no httppost – Greeed Commented Mar 25, 2014 at 13:04
1 Answer
Reset to default 5You can use Ajax function as follows :
$.ajax({
url: "/Controler/Action",
data: { 'Id': groupId },
type: 'GET',
success: function (result) {
//do the necessary updations
},
error: function (result) {
}
});
You can also try form submission as follows :
@using (Html.BeginForm("Action", "Controller", FormMethod.GET))
{
// do your html
<input type="submit" value="save"/>
}
本文标签: javascriptCalling ActionResult method from the View using jsStack Overflow
版权声明:本文标题:javascript - Calling ActionResult method from the View using js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744017848a2576662.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论