Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在同一控制器Asp.net Mvc中执行Post操作时,参数丢失值_C#_Asp.net_Asp.net Mvc_Asp.net Web Api_Http Post - Fatal编程技术网

C# 在同一控制器Asp.net Mvc中执行Post操作时,参数丢失值

C# 在同一控制器Asp.net Mvc中执行Post操作时,参数丢失值,c#,asp.net,asp.net-mvc,asp.net-web-api,http-post,C#,Asp.net,Asp.net Mvc,Asp.net Web Api,Http Post,我只想在控制器名称Home中的Mvc操作结果上发布同一控制器中的操作结果,post请求发送成功,但参数丢失传递值 从主控台呼叫Post [ValidateInput(false)] [HttpPost] public ActionResult addToWishList(string customcode, string addcusimgSVG, string pagestatus = "", string userinformation="") {

我只想在控制器名称Home中的Mvc操作结果上发布同一控制器中的操作结果,post请求发送成功,但参数丢失传递值

从主控台呼叫Post

   [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

    }
同一控制器中存在addToWishList调用的操作结果

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

     //serviceAndVisitorModel is null 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; }
}

请告诉我这段代码有什么问题。

尝试通过JSON发送

using Newtonsoft.Json;


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

PS您需要通过nuget安装Newtonsoft.Json

您是否尝试过该型号???什么是
服务和VisitroData
?(AllserviceWebApi serviceAndVisitorModel的
参数建议您要绑定到复杂对象-您不能将
字符串
绑定到复杂对象)@StephenMuecke请建议我如何绑定?我猜不出
AllserviceWebApi
是什么,或者
ServiceAndVisitroData的值是什么is@StephenMuecke请考虑我现在编辑的问题。
using Newtonsoft.Json;


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