如何使用ASP.NET MVC控制器动作的jQuery get方法?

Sae*_*ati 2 ajax jquery partial-views asp.net-mvc-3

我想使用部分视图的jQuery get方法.最好的方法是什么?我读到了jQuery get,对我来说最简单的方法是这段代码:

$.get(@Url.Action('Controller', 'Action'), function () { });
Run Code Online (Sandbox Code Playgroud)

Dar*_*rov 5

你只是错过了网址周围的引号,搞砸了Url.Action帮助器语法.这是正确的方法:

$.get('@Url.Action("Action", "Controller")', function (result) { 
    // TODO: process the results of the server side call
});
Run Code Online (Sandbox Code Playgroud)

请注意传递给$ .get方法的url周围的单引号和Url.Action帮助程序的签名.