简体   繁体   English

从WebMethod返回对象(AJAX ASP.net)

[英]Return Object from WebMethod (AJAX ASP.net)

I Have an object 'Person' in C#, and I want to return this object in WebMethod. 我在C#中有一个对象“ Person”,并且我想在WebMethod中返回该对象。

  [WebMethod]
    public static Person LoadPerson(string id)
    {
      return sdb1.Persons.Where(x =>x.PersonID.ToString().Equals(id)).FirstOrDefault();   
    }

and in JS: 在JS中:

function LoadPerson(id) { 函数LoadPerson(id){

    PageMethods.LoadPerson(id,onSucess, onError);

    function onSucess(result) {
        alert();
    }

    function onError(result) {
        alert('Something wrong.');
    }

   }

How can I return this object? 如何退回该物品? I want for example to alert onSucess the Person fullName. 例如,我想提醒onSucess个人全名。 (there is Attribute field 'FullName') (有“属性”字段“全名”)

Thank you! 谢谢!

You can just return it. 您可以退货。

When you add this Client in your front-end or another application, the webmethod object will contains your returning object. 当您将此客户端添加到前端或其他应用程序中时,webmethod对象将包含您的返回对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM