使用 Postman 将 GUID 列表发布到 MVC 5 控制器

Posting a List of GUIDs to a MVC 5 Controller with Postman(使用 Postman 将 GUID 列表发布到 MVC 5 控制器)
本文介绍了使用 Postman 将 GUID 列表发布到 MVC 5 控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个控制器方法:

public String CreateGasolineBlend(List<Guid> enumerableTransferIDs){//细节}

接受 GUID 列表.但是,当我使用邮递员时,列表始终为空.

我尝试使用这篇文章来了解如何格式化请求:

I'm attempting to make a controller method:

public String CreateGasolineBlend(List<Guid> enumerableTransferIDs)
    {
        //Details
    }

Accept a list of GUIDs. However, the list is always null when I'm using postman.

I tried using this article to find out how to format the request:

Is it possible to send an array with the Postman Chrome extension?

But I'm unsure if MVC even is capable of accepting a List of objects using a Post Method, or if perhaps I am incorrectly formatting the POST request in Postman.

(I am using what the previous stack overflow question states, arr[0], arr[1] or arr[], arr[] with Guids as values.)

Is my problem with the way I'm receiving the values in the controller, or is it a problem with how I'm using Postman?

解决方案

MVC is capable of accepting a list objects and map it to the action method parameter.

You need to make sure you are using the correct Content-Type header value when send the data. "application/json" should work.

I just updated your action method to return the posted data along with the item count in a json structure to verify this.

[HttpPost]
public ActionResult CreateGasolineBlend(List<Guid> enumerableTransferIDs)
{
    return Json(new { ItemCount= enumerableTransferIDs.Count(),
                      Items= enumerableTransferIDs});
}

You can see the response came back with the data we posted.

这篇关于使用 Postman 将 GUID 列表发布到 MVC 5 控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)