Hi mahesh213,
Check this example. Now please take its reference and correct your code.
Database
CREATE TABLE UserDetails(Id INT PRIMARY KEY,UserName VARCHAR(20),Password VARCHAR(50),Mobile BIGINT)
INSERT INTO UserDetails VALUES(1,'mahesh','mahesh',1122222222)
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
public JsonResult SendPassword(int mobileNumber)
{
string message = "Mobile number does not registered with us.";
TestEntities entities = new TestEntities();
UserDetail user = entities.UserDetails.Where(x => x.Mobile == mobileNumber).FirstOrDefault();
if (user != null)
{
string password = user.Password;
if (!string.IsNullOrEmpty(password))
{
// Code for sending password to mobile.
message = "Password has been sent to your mobile number.";
}
}
return Json(message, JsonRequestBehavior.AllowGet);
}
}
View
<html>
<head>
<title>Index</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', []);
app.controller("MyController", function ($scope, $http, $window) {
$scope.SendPassword = function () {
$http.get("/Home/SendPassword/", { params: { mobileNumber: $scope.MobileNumber} })
.then(function (response) {
$scope.Message = response.data;
if (response.data == 'Mobile number does not registered with us.') {
$scope.Color = "Red";
}
else if (response.data == 'Password has been sent to your mobile number.') {
$scope.Color = "Green";
}
$scope.MobileNumber = "";
}).then(function (response) {
$scope.Message = response.responseText;
});
}
});
</script>
</head>
<body>
<div ng-app="MyApp" ng-controller="MyController">
<input type="text" name="mobilenumber" ng-model="MobileNumber" />
<input type="button" value="Send Password" ng-click="SendPassword()" />
<br />
<span ng-style="{color:Color}" ng-bind="Message"></span>
</div>
</body>
</html>
Screenshot
For sending SMS code you can refer below link or you can write code for sending SMS using any API availabel with you.