Hi Every Body
I solved my problem with bellow solution:
JavaScript Part:
<script>
function Like(ID)
{
var xmlhttp;
var pageurl = "/Note/Like/" + ID
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("NoteLikeCounter").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",pageurl,true);
xmlhttp.send();
}
</script>
Controller Part:
public int Like(long id)
{
FaezEntities entity = new FaezEntities();
Note note = entity.Notes.SingleOrDefault(a => a.ID == id);
string user = Request.UserHostAddress;
bool exist = false;
foreach (NoteUserAddress item in entity.NoteUserAddresses.Where(a => a.NoteID == id))
if (item.UserAddress == user)
exist = true;
if (exist == false)
{
note.LikeCount++;
entity.SaveChanges();
}
return note.LikeCount;
}
View Part:
<input type="button" class="Note-Like-Image" önclick="Like(@item.ID)" />
Thank you for your attention specially Thank you "Sampath Lokuge".
I hope this solution can help you.