Hi mahesh213,
Check this example. Now please take its reference and correct your code.
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
[HttpPost]
public JsonResult GreetingMessage()
{
string message = "";
// Runs at every dat 12 AM.
if (DateTime.Now.Hour == 0 && DateTime.Now.Minute == 0)
{
// Assign Greeting message whose DOB falls on Today's Date based on LoggedIn User.
string query = "SELECT Name FROM Employee WHERE DATEPART(DAY, DOB) = @Day AND DATEPART(MONTH, DOB) = @Month AND Name = @Name";
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Day", DateTime.Today.Day);
cmd.Parameters.AddWithValue("@Month", DateTime.Today.Month);
cmd.Parameters.AddWithValue("@Name", Session["UserName"]);
con.Open();
message = string.Format("<b>Happy Birthday </b>{0}<br /><br />Many happy returns of the day.", Session["UserName"]);
con.Close();
}
}
}
return Json(message);
}
}
View
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Index</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.8/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module("MyApp", []);
app.controller("MyController", function ($scope, $http, $sce) {
DisplayGreeting();
function DisplayGreeting() {
$http({
method: "POST"
, url: "Home/GreetingMessage/"
}).then(function (response) {
if (response.data != '') {
$scope.Message = $sce.trustAsHtml(response.data);
}
}, function (response) {
$scope.Message = response.responceText;
})
}
});
</script>
</head>
<body>
<div ng-app="MyApp" ng-controller="MyController">
<div style="z-index: 1; position: relative; background-color: #0090CB; width: 20%;
height: 100%; padding: 20px; color: white; text-align: center;">
<span ng-bind-html="Message"></span>
</div>
</div>
</body>
</html>