0

I am trying to pass Mobile Number in Asp.NET MVC Core Web API's. For example https://api.test.com/GetMobileNumberAvailability/+971 99 999 9999/

My Controller file part looks like this:

[HttpGet("GetMobileNumberAvailability/{mobile}")]
public async Task<ActionResult<Client>> GetMobileNumberAvailability(string mobile)
{
    var client = await _context.Clients.Where(client => client.Mobile == mobile).FirstOrDefaultAsync();
    if (client == null)
    {
        return null;
    }
    return client;
}

Can anyone help how to deal with this?

4
  • You need to UrlEncode it from the caller side and decode it in your GetMobileNumberAvailability action. Commented Apr 20, 2020 at 13:44
  • Can you please help me with some example ? I would be really obliged. Commented Apr 20, 2020 at 14:00
  • I would need to know the way you are calling that function from the frontend. Could you please update your Question, and include the front-end bits? Commented Apr 20, 2020 at 14:22
  • trying to pass Mobile Number in Asp.NET MVC Core Web API You can check this SO thread: stackoverflow.com/a/49679099/6751634 Commented Apr 21, 2020 at 9:52

1 Answer 1

0

Encode the mobile number before hitting the endpoint. It looks like https://api.test.com/GetMobileNumberAvailability/%2B971%2099%20999%209999/
and decode the mobile

[HttpGet("GetMobileNumberAvailability/{mobile}")]
        public async Task<ActionResult<Client>> GetMobileNumberAvailability(string mobile)
        {
            mobile = System.Net.WebUtility.UrlDecode(mobile).Trim();
            var client = await _context.Clients.Where(client => client.Mobile == mobile).FirstOrDefaultAsync();
            if (client == null)
            {
                return null;
            }
            return client;
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.