I want to pass an empty string to C# web api from javascript. But when i pass empty string from typescript i get null in the webapi parameter. How to pass empty string?
here is my client web api call:
public ChangePassword(username: string, oldPassword: string, newPassword: string) {
const oldPwd = (oldPassword === null || oldPassword === undefined) ? '' : oldPassword;
const newPwd = (newPassword === null || newPassword === undefined) ? '' : newPassword;
const endPointUrl: string = this.webApi.EndPoint + '/Authentication/ChangePassword';
const parameters = new HttpParams()
.set('username', username)
.set('oldPassword', oldPwd)
.set('newPassword', newPwd);
return this.httpClient.post(endPointUrl, '', { params: parameters });
}
And my web api is
[HttpPost]
public void ChangePassword(string userName, string oldPassword, string newPassword)
{
WebServiceFault fault = _securityManager.ChangePassword(userName, oldPassword, newPassword);
if (fault == null)
{
return;
}
throw WebApiServiceFaultHelper.CreateFaultException(fault);
}
When i pass null as parameter for old and new password to the ChangePassword()
method i get the string as null in the web api method insted of getting an empty string.