C# 在同一控制器Asp.net Mvc中执行Post操作时,参数丢失值
我只想在控制器名称Home中的Mvc操作结果上发布同一控制器中的操作结果,post请求发送成功,但参数丢失传递值 从主控台呼叫PostC# 在同一控制器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="") {
[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));
}