I have a controller with typical views (Index, Create, Edit, Delete). In index I show a list of object attributes. I.E. Books
===============================
ID || Title || Author || % Read
-------------------------------
1 || Haaa || Oksdkds|| 90
===============================
Ihe field %Read can change while viewing the page. Is there any way to check via ajax if this field has changed, and update it?
My suggestion is below :
Use Timer to keep updating the Read like below
setInterval("YourFunctionName();", 1000); //Time is in milliseconds
JQuery/JavaScript
<script type="text/javascript">
function YourFunctionName() {
var Istrue = false;
$.ajax({
url : "@Url.Action("ControllerName", "ActionName")",
contentType : "application/json; charset=utf-8",
dataType : "json",
type : "GET", //For non complex data only
data : JSON.stringify({ param1:'Value1' })
}).done(function(Result) {
//Update the Read Field here like below
$('ID').html(Result.Value)
})
.fail(function() {
});
}
</script>
Action Method
[HttpGet]
public JsonResult ActionName()
{
return Json(new { Value = 10 }, JsonRequestBehavior.AllowGet);
}