2017-11-02 3 views
-1

コントローラの名前がのホームにあるMvcアクションの結果に投稿したいのですが、同じコントローラーのアクション結果からポストリクエストは正常に送信されますが、パラメーター通過価値を失った。ポスト同じコントローラーでアクションをポストしたときに値が失われる

[Route("services")] 
    [HttpPost] 
    public ActionResult services(AllserviceWebApi serviceAndVisitorModel, string pagename = "service")//string selectedService,string userId,string DealInfo 
    { 

    //serviceAndVisitorModel is null here 

    } 

同じコントローラでaddToWishListの存在によって呼び出され、アクション結果

[ValidateInput(false)] [HttpPost] public ActionResult addToWishList(string customcode, string addcusimgSVG, string pagestatus = "", string userinformation="") { string URI = "http://localhost:49389/services"; string myParameters = "serviceAndVisitorModel=" + ServiceAndVisitroData; using (WebClient wc = new WebClient()) { wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; string HtmlResult = wc.UploadString(URI, myParameters); } //return some view here } 

コントローラーホームからモデル

public class AllserviceWebApi 
{ 
    public string packageTypeID { get; set; } 
    public string packageTypeCode { get; set; } 
    public string pageUrl { get; set; } 
    public string pageName { get; set; } 
    public string displayName { get; set; } 
    public string name { get; set; } 
    public List<pakageInfoList> packageInfoList { get; set; } 
    //------visitor object 
    public string IPAddress { get; set; } 
    public string deviceName { get; set; } 
    public string OSName { get; set; } 
    public string browserName { get; set; } 
    public string countryName { get; set; } 

    public string selectedService{ get; set; } 
    public string userId{ get; set; } 
    public string OrderId { get; set; } 
    public string DealInfo { get; set; } 
    public long wishlishid { get; set; } 
    public string customlogoCode { get; set; } 
    public string customLogoImgSvg { get; set; } 
    public bool IsCustomllogo { get; set; } 
} 
012を呼び出す

AllserviceWebApi ServiceAndVisitroData = new AllserviceWebApi() 
      { 
       selectedService = serviceids, 
       userId = "0", 
       OrderId = "0", 
       DealInfo = "", 
       IPAddress = ipaddress, 
       // deviceName: userDevicedata[0], 
       OSName = osandversion, 
       browserName = browsermajorversion, 
       wishlishid = wishid, 
       customlogoCode = logocode, 
       customLogoImgSvg = logosvg, 
       IsCustomllogo = true 

      }; 

の初期モデルは、いただきました!このコードの間違った教えてください。

+0

nuget経由Newtonsoft.Jsonをインストールするには、あなたの必要性を、それを送信します? – Saurabh

+0

'ServiceAndVisitroData'とは何ですか? ( 'AllserviceWebApi serviceAndVisitorModel'パラメータは、複雑なオブジェクトにバインドすることを示唆しています。複雑なオブジェクトに' string'をバインドすることはできません) –

+0

@StephenMueckeこれをバインドする方法を教えてください。 – DumpsterDiver

答えて

1

てみJSON経由

using Newtonsoft.Json; 


    using (WebClient wc = new WebClient()) 
      { 
       wc.Headers[HttpRequestHeader.ContentType] = "application/json"; 
       string HtmlResult = wc.UploadString(URI, JsonConvert.SerializeObject(ServiceAndVisitroData)); 
      } 

PSあなたがモデルを試してみました

関連する問題