[RESOLVED]convert Razor IsPost to Ajax Post

I have the following action on a page that allows a user to follow and unfollow another user, but the form processes on the same page and refreshes, which I do not want for austerity and convenience sake.. Can I get help with the AJAX method

        @if(menu>0){
var count= Convert.ToInt32(db.QueryValue("select * from Following WHERE User_Id=@0 and UserID=@1",visitor.UserID,WebSecurity.GetUserId(WebSecurity.CurrentUserName)));
if(count<1){
    if(IsPost){ 
    var sql = @"INSERT INTO Following (User_ID,UserID) VALUES (@0,@1)";
        db.Execute(sql,visitor.UserID,WebSecurity.GetUserId(WebSecurity.CurrentUserName));
        string currentUrl =  Request.Url.LocalPath;
 Response.Redirect(currentUrl);
}
 
    <form action="" method="post">
  
    <div class="hero-actions button-set">
<div><input class='btnn btn-default btn-round-lg btn-lg' id='@nav.UserID' name="follow" type="submit" value="Follow"></div>
<div style='display:none'><input class='btnn btn-default btn-round-lg btn-lg del' id='@nav.UserID' value="Following" name="following" type="submit"></div>
</div>
    </form>
}

I would go on with it this way

Leave a Reply