0
{"__type":"CountryModel","dt":null,"ds":null,"dtRow":null,"strSQL":{"Capacity":16,"MaxCapacity":2147483647,"Length":0},"iCnt":0,"ConnType":"FP","Code":"AE","Value":"United Arab Emirates"},{"__type":"CountryModel","dt":null,"ds":null,"dtRow":null,"strSQL":{"Capacity":16,"MaxCapacity":2147483647,"Length":0},"iCnt":0,"ConnType":"FP","Code":"AF","Value":"Afghanistan"},{"__type":"CountryModel","dt":null,"ds":null,"dtRow":null,"strSQL":{"Capacity":16,"MaxCapacity":2147483647,"Length":0},"iCnt":0,"ConnType":"FP","Code":"AG","Value":"Antigua and Barbuda"},

これはjsonで返すwebmethodですが、問題は、継承元の基本クラスからのasp.netの戻り値です。これを解決するにはどうすればよいですか? 動作していますが、値を返したくないのでデータが無駄になっていますか?

BaseModel.cs

   public string ConnType="";
   public datatable dt;

CountryModel.cs:

public class CountryModel:BaseModel{
   public List<MenuFunctionModel> AssignList()
{
    var _List = new List<MenuFunctionModel>();

    foreach (DataRow dr in dt.Rows)
    {
        _List.Add(new MenuFunctionModel
        {
            Code = dr["Code"].ToString(),
            Title = dr["Title"].ToString(),
            Description = dr["Description"].ToString(),
            Location = dr["Location"].ToString() + dr["FileName"].ToString()
        });
    }
    return _List;
}
}

ウェブサービス API:

    [WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List<CountryModel> loadCt()
{
    CountryModel _Country = new CountryModel();
    _Country.SelectAll();
    return _Country.AssignList();
}
4

1 に答える 1

1

WebMethod から任意の型を次のように返すことができます。

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static Object loadCt()
{
    CountryModel _Country = new CountryModel();
    _Country.SelectAll();
    return _Country.AssignList().Select(m=> new{ Code=m.Code, Title =m.Title}); //select those fields only which you want to return
}

その他の参照については、ここをクリックしてください

于 2013-06-18T10:04:24.567 に答える