-1

I would like to just post on Mvc Action result which is in controller name Home from an Action result in same controller,the Post request send successfully but the parameters lost passing value.

Calling Post From Controller Home

   [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

    }

Action Result Called by addToWishList present in same Controller

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

     //serviceAndVisitorModel is null here

    }

Model

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; }
}

Model Initializing

 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

            };

Please tell me whats wrong with this code.

TAHA SULTAN TEMURI
  • 4,031
  • 2
  • 40
  • 66

1 Answers1

1

Try to send it via JSON

using Newtonsoft.Json;


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

PS your need to install Newtonsoft.Json via nuget

itikhomi
  • 1,560
  • 13
  • 13