I have a server-side model with a datetime type field PublishDate. I am sending List<Posts> as json in response to ajax call.
I would like to use c# code Convert.ToDateTime(this.PublishDate).ToString("MMM dd, yyyy") in jquery code. Below is my code what I tried so far-
var posts = response.Posts;
$.each(posts, function () {
$('#container').append('<div class="row">
<div class="col-lg-12">
<h2>' + this.PostTitle + '</h2>
<span>Published on: @Convert.ToDateTime(this.PublishDate).ToString("MMM dd, yyyy")</span></div></div>');
});
But it's not working. Any idea?
PublishDate?Convert.ToDateTime()if its already aDateTime- just@PublishDate.ToString("MMM dd, yyyy")but this does not make a lot of sense since razor code is parsed on the server. Is this part of an ajax callback?