In ASP.NET Core I am trying to pass a value from ajax to view, I have an action that passes an int
value to an ajax call, and from there, ajax tells my view to blink or not. Here is the controller
public ActionResult GetCounselingCount()
{
var result = 0;
try
{
var Counseling = _context.TableName.Where(f => f.FolderStatusId == 12)
.Where(f => f.IsActive == true).Count();
if (Counseling != 0)
{
result = Counseling;
}
}
catch (Exception)
{
throw;
}
return Json(result);
}
result is passed to my ajax call
$.ajax({
dataType: "json",
url: window.location.origin + "/ControllerName/GetCounselingCount",
success: function (result) {
if (result != 0) {
$('#phaSection').addClass("blinking");
}
else {
if ($('#phaSection').hasClass("blinking")) {
$('#phaSection').removeClass("blinking");
}
}
}
});
This works fine when I pass <li id="phaSection"> to my view,
<li id="phaSection" class="nav-item @((ViewContext.RouteData.Values["Controller"].ToString() == "ControllerName") && (ViewContext.RouteData.Values["Action"].ToString() == "Counseling") ? "active" : "")">
<a class="nav-link" asp-controller="ControllerName" asp-action="Counseling">
<i class="fas fa-book-reader"></i>
<span>Counseling</span>
</a>
</li>
This causes <span>Counseling</span> to blink as expected, however my question is how can I pass the int value result from my ajax to be displayed in my view? Instead of my view <span>Counseling</span>, I want it to be
<span>Counseling + "value"</span>