【发布时间】:2017-11-02 10:12:03
【问题描述】:
我只想在同一控制器中的动作结果中发布控制器名称 Home 中的 Mvc 动作结果,发布请求成功发送但参数丢失了传递值。
从控制器主页调用帖子
[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; }
}
模型初始化
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
};
请告诉我这段代码有什么问题。
【问题讨论】:
-
你试过模型吗???
-
什么是
ServiceAndVisitroData? (AllserviceWebApi serviceAndVisitorModel参数建议您要绑定到复杂对象 - 您不能将string绑定到复杂对象) -
@StephenMuecke 请建议我如何绑定这个?
-
我猜不出
AllserviceWebApi是什么或者ServiceAndVisitroData的值是什么 -
@StephenMuecke 请考虑我编辑的问题
标签: c# asp.net asp.net-mvc asp.net-web-api http-post