为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 WebAPI 的控制器中传递输出参数

如何在 WebAPI 的控制器中传递输出参数

C#
幕布斯7119047 2023-09-16 15:02:58
这里我从存储过程中检索输出参数Entity Framework(EDMX)(输出参数是TransactionId)这里我想将TransactionId值传输到Scdid(在下一篇文章方法中)如何获取TransactionId = Scdid in the controller我的API代码是 public class StockcountheaderController : ApiController{    private adminv2Entities enqentities = new adminv2Entities();    [HttpPost]    private  void Stock([FromBody] List<spGetNewStockCountHeader_Result> jsonvalues)    {        foreach (spGetNewStockCountHeader_Result Datastock in jsonvalues)        {            ObjectParameter TransactionId = new ObjectParameter("TransactionId", typeof(Int32));            spGetNewStockCountHeader_Result Stockobject = new  spGetNewStockCountHeader_Result();            Stockobject.UserID = Datastock.UserID;            Stockobject.created = Datastock.created;            Stockobject.CompanyID = Datastock.CompanyID;            Stockobject.modified = Datastock.modified;            Stockobject.modifieduserid = Datastock.modifieduserid;            Stockobject.confirm = Datastock.confirm;            Stockobject.ShopId = Datastock.ShopId;            enqentities.spGetNewStockCountHeader(Datastock.UserID,  Datastock.created,                 Datastock.CompanyID, Datastock.modified,  Datastock.modifieduserid, Datastock.confirm,                Datastock.ShopId, TransactionId);        }    }    }
查看完整描述

1 回答

?
守着一只汪

TA贡献1872条经验 获得超3个赞

对问题进行详细讨论后,发现存储过程未正确返回 OUTPUT 参数。上述问题的最终解决方案需要修改代码:


[HttpPost]

private  IActionResult Stock([FromBody] List<spGetNewStockCountHeader_Result> jsonvalues)    

{

  ObjectParameter TransactionId = new ObjectParameter("TransactionId", typeof(Int32));

  foreach (spGetNewStockCountHeader_Result Datastock in jsonvalues)

  {


    spGetNewStockCountHeader_Result Stockobject = new spGetNewStockCountHeader_Result();

    Stockobject.UserID = Datastock.UserID;

    Stockobject.created = Datastock.created;

    Stockobject.CompanyID = Datastock.CompanyID;

    Stockobject.modified = Datastock.modified;

    Stockobject.modifieduserid = Datastock.modifieduserid;

    Stockobject.confirm = Datastock.confirm;

    Stockobject.ShopId = Datastock.ShopId;

    enqentities.spGetNewStockCountHeader(Datastock.UserID, Datastock.created, Datastock.CompanyID, Datastock.modified, Datastock.modifieduserid, Datastock.confirm,Datastock.ShopId, TransactionId);

  }

return Ok(new { data = TransactionId.Value});    

}

在 Angular 应用程序中获取该TransactionId值后,您可以使用该值将其作为查询字符串或 POST 正文中的参数发送到下一个方法。


查看完整回答
反对 回复 2023-09-16
  • 1 回答
  • 0 关注
  • 89 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信