2017-09-20 18 views
0

非常に簡単な質問がありますが、回答が見つかりません。私は複数のフィールドを持つモデルを持っています。例:.NetクライアントからWebApiサーバにモデルを送信

public class BillingInfoViewModel 
{ 
    //Distributor Information 
    public string DistributorName { get; set; } 
    public string DistributorEmail { get; set; } 
    public string DistibutorPhone { get; set; } 
    public CompanyCode CompanyCode { get; set; } 

    //ECU information 
    public string EcuName { get; set; } 
    public string EcuPartNumber { get; set; } 
    public string EcuProgramName { get; set; } 

    //Lot of fields 
} 

サーバーに送信する必要がある情報です。私はそれをどのようにすることができますか?このフィールドを1つずつ送信する必要がありますか?

public void ApiController(string DistributorName, string DistributorEmail, ..othern fields) 

私はすべてのオブジェクトを送信する必要がありますか?

public void ApiController(BillingInfoViewModel model) 

P.S.

public class BillingController{ 

public IHttpActionResult Post([FromBody]BillingInfoViewModel model){ 
// HERE YOU GET THE BillingInfoViewModel obj from the call (in POST) 
} 

} 

はそれが

+1

、JSONとしてこのデータを送信します。 JSONプロパティ名は、モデルクラスBillingInfoViewModelの同じプロパティ名である必要があります。 – Amit

+0

モデル全体をjsonオブジェクトにシリアル化して送信できます。 –

答えて

1

通常、助けを願って:あなたは

例えばこれを試してAsp.NET WebAPIのを使用している場合、私はSystem.Net.Http.HttpClient

1

で情報を送ります複雑なパラメータータイプはPOST動詞と共に渡されます。 GET動詞を使うことができますが、ブラウザーにURLの制限があり、パラメーターが表示されます。ここでは、要件を実装するいくつかの方法を紹介するパラメータバインディングの詳細ガイドがあります。クライアントからサーバーへ

https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api

関連する問題