try this
Create an Action Method to return the time string.
Controller:
public ActionResult GetTime()
{
return Json(DateTime.Now.ToLongTimeString());
}
View:
<div id="div1">
@DateTime.Now.ToLongTimeString()
</div>
<button onclick="refreshTime()">Refresh</button>
<script>
function refreshTime() {
var url = '@Url.Action("GetTime","Home")'
$.ajax({
url: url,
data: { },
type: "post",
success: function (time) {
$('#div1').html(time);
},
error: function () {
alert('error');
}
});
}
</script>