最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Calling ActionResult method from the View using js - Stack Overflow

programmeradmin0浏览0评论

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 with HttpPost 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
Add a ment  | 

1 Answer 1

Reset to default 5

You 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"/>
}
发布评论

评论列表(0)

  1. 暂无评论