如何将数据作为表单数据从另一个控制器传递到webapi

How to pass data as a Form data to webapi from another controller

提问人:Sohini 提问时间:11/14/2023 更新时间:11/14/2023 访问量:26

问:

我正在将对象从 UI 发送到 API 控制器。下面是 UI 中的控制器

public async Task<ActionResult> Update(string Id, string Desc..)
{
   ViewBag.API_CORE_URL = _config["API_CORE_URL"];
   Object obj = new Object();
    
   obj.ScenarioId = Id;
   obj.ScenarioDesc = Desc;
   using (var client = new HttpClient())
   {
    client.DefaultRequestHeaders.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("multipart/form-data"));
        var result = client.PostAsJsonAsync($"{ViewBag.API_CORE_URL}api/Account/ExecuteObj", obj).Result;
    return Ok(result);
   }
}


//WebAPI Controller
[HttpPost]
[Route("ExecuteObj")]
public async Task<IActionResult> ExecuteObj([DataSourceRequest] DataSourceRequest dataSourceRequest, [FromForm]ExecuteDataSourceRequest executeDataSourceRequest)
{
    if (HttpContext.User.Identity.Name != null)
    {
        DvfwUser user = await _userManager.FindByNameAsync(HttpContext.User.Identity.Name);
        executeDataSourceRequest.UserId = user.ssoUserId;
        DataSourceRequestMapHelper.SetDataRequestObject(executeDataSourceRequest, dataSourceRequest);
        var executionSummaries = _accountRepository.GetExecutedata(executeDataSourceRequest);

        return Ok(executionSummaries);
    }
    else
        return Unauthorized();
}

我在executeDataSourceRequest中没有得到任何值。如何从 UI 中获取我正在暂停的对象?

C# asp.net

评论

0赞 Jeevan ebi 11/14/2023
请将请求 URL 和示例有效负载添加到描述中

答: 暂无答案