与ASP.Net MVC PageMethods [英] PageMethods with ASP.Net MVC
问题描述
我发现ASP.Net PageMethods非常方便和易于使用,但我刚开始使用MVC开发,我不知道如何使用它们?
什么是 PageMethods.MyFunction相当于()
在MVC,其中myFunction是一个控制器动作?
我知道我可以使用的Json
函数返回一个值,但我怎么调用客户端的动作?
我知道我可以使用JSON功能
返回一个值,但我怎么叫
从客户的行动?
块引用>我认为你正在寻找要么的getJSON
$。的getJSON(/控制器/动作功能(JSON)
{
警报(JSON数据:+ json.users [3]。名称);
});或 AJAX jQuery的方法。
这两者都可以调用操作并获取JSON数据从ASP.NET MVC回来很容易。
I have found ASP.Net PageMethods very handy and easy to use, but I have just started developing using MVC and am not sure how to use them?
What is the equivalent of
PageMethods.MyFunction()
in MVC where MyFunction is a Controller action?I know I can use the
Json
function to return a value, but how do I call the action from the client?解决方案I know I can use the Json function to return a value, but how do I call the action from the client?
I think you're looking for either getJSON
$.getJSON("/controller/action", function(json) { alert("JSON Data: " + json.users[3].name); });
or the ajax jQuery method.
Either can call an action and get JSON data back from ASP.NET MVC very easily.
这篇关于与ASP.Net MVC PageMethods的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!