0

I have created a C# MVC4 Web api using VS2010. When I try to debug with calling the api (http://localhost/APITest/test?data=12345-45678-890), then the system returned action + parameters ["test?data=12345-45678-890"] as filename and asking to save the file. I can't open or save the file totally. May I know where does it causing the problem?

Thanks in advance.

Try searching around can't really find similar problem I faced.

    [HttpGet]
    public DocumentModel Test(String data)
    {
        List<DocumentModel> doc = new List<DocumentModel>();
        DocumentModel docObj;
        docObj.Name = "Venom";
        docObj.Decription = "Fiction story";            
        docObj.Remarks = "Remarks";
        doc.Add(docObj);
        return docObj;
    }

Supposedly return the DocumentModel as json string.

user3607582
  • 61
  • 11

2 Answers2

0

You could set the method signature to return ActionResult:

public ActionResult Test(String data)

...and then wrap your return object with Json():

return Json(docObj);

Check this SO question for more examples.

kaffekopp
  • 2,551
  • 6
  • 13
  • Manually encoding the result is against the principles of WebAPI, where you return the object itself, and then the framework decides how to encode it based on the context (in JSON, in XML etc). – GSerg Jan 10 '19 at 08:41
0

Thanks for all the reply. I found the problem root caused its due to there is multiple [HttpGet] action in my APiController. I got the actual error messages from the browser after deployed to IIS and do a test run. It's give the error "Multiple actions were found that match the request". But it's doesn't give any error during running VS2010 debugging and directly prompt the filename with action+parameters on the browser. After do some search and found below link and solved the problem.

https://hassantariqblog.wordpress.com/2015/11/30/webapi-multiple-actions-were-found-that-match-the-request/

Thank you very much.

user3607582
  • 61
  • 11