Base solution for your next web application
Open Closed

RETURN TYPE TEXT/PLAIN #9780


User avatar
0
alfar_re created

Hi,

I'm trying to return type text/plain to respond to a certain external API call.

I'm receiving this;

{ "result": "Welcome to Service\nSelect a service.\n1: Register\n2: Help\n#: Exit.", "targetUrl": null, "success": true, "error": null, "unAuthorizedRequest": false, "__abp": true }

But I'd like to receive just this;

Welcome to Service Select a service. 1: Register 2: Help #: Exit

  • 9.1
  • MVC
  • .net core

10 Answer(s)
  • User Avatar
    0
    alfar_re created

    Hi,

    Is it possible to get help on this?

  • User Avatar
    1
    zony created
    Support Team

    Hi alfar_re, You can use the [DontWrapResultAttribute] feature on the interface to prohibit ABP from wrapping the return value.

  • User Avatar
    0
    alfar_re created

    Hi zony,

    I did that but I still get the same result.

  • User Avatar
    0
    zony created
    Support Team

    Hi alfar_re, I upload a DEMO project later, and the features worked normally in my project.

  • User Avatar
    0
    alfar_re created

    Hi,

    Do you mean I should try on a different project and see if it works?

  • User Avatar
    0
    zony created
    Support Team

    Hi alfar_re, It works in my project.

    public class DemoDto
    {
        public string Name { get; set; }
    
        public int Age { get; set; }
    }
    
    [Route("/api/demo")]
    public class DemoController : AbpController
    {
        [HttpGet]
        [Route("/abp-wrap-result")]
        public Task<DemoDto> AbpWrapResultAsync()
        {
            return Task.FromResult(new DemoDto
            {
                Name = "A",
                Age = 11
            });
        }
    
        [DontWrapResult]
        [HttpGet]
        [Route("/no-wrap-result")]
        public Task<DemoDto> NoWrapResultAsync()
        {
            return Task.FromResult(new DemoDto
            {
                Name = "A",
                Age = 11
            });
        }
    }
    

  • User Avatar
    0
    alfar_re created

    Hi @zony,

    I see. Thanks for making this clear. Let me try it out.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @alfar_re

    Did you have a chance to try this ?

  • User Avatar
    0
    alfar_re created

    Hi @ismcagdas,

    Apologies I'd lost track on this. Yes I did, it worked perfectly.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Great :)