Click here to Skip to main content
15,894,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        public IEnumerable<string> Get(int id)
        {
            return new string[] { "sa1", "sa2" };
        }
        [HttpGet]
        public IEnumerable<string> password()
        {
            return new string[] { "password", "password" };
        }

But When i try to call http://localhost:49365/api/mycontrollername/password it's always showing The request is invalid.
It is never calling a password method
Posted

1 solution

See the example
I return the object that contains ErrorCode & JsonResult (i.e List of Physician) from server side
C#
public Result Get()
        {
            try
            {
                OResult.ErrorCode = 0;
                OResult.JsonResult= OPhysicianRepository.GetAllPhysician();                
                return OResult;
            }
            catch
            {
                OResult.ErrorCode = 1;
                OResult.JsonResult = null;              
                return OResult;
            }
        }


To Call on Physician view
JavaScript
$.getJSON('/api/physician', function (contactsJsonPayload) {
        $(contactsJsonPayload.JsonResult).each(function (i, item) {
            $('#physician').append('<li>' + item.name + '</li>');
        });
    });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900