title: return javascript from asp.net action
body: <p>I'm working on a site where users can add points to other user, however once a user added a point to other particular user he cannot add more points to the same user. So user1 can only give one point to user2.</p>
  
  <p>On the server I check if there already exists a point with the same username. Everything works nicely so what I want to do now is to inform a user with some kind of message that he cannot add more points when he tries to do so since he already did add a point before. I think what i need is to return javascript from the server that will display the message. But maybe there is some other solution to this. Here is my action in controller:</p>
  
  <pre><code>[HttpPost]
      public ActionResult AddPointAndCopyCurrentFavToPlaylist(int id)
      {
          if (CheckIfPointExists(User.Identity.Name, id))
          {
          var originalSong = repository.GetCurrentFav(id);
  
          var newSong = new Song();
          newSong.UserName = User.Identity.Name;
          newSong.Title = originalSong.Title;
          newSong.YoutubeLink = originalSong.YoutubeLink;
          newSong.GenreId = 38;
          newSong.Date = DateTime.Now;
          repository.AddSong(newSong);
  
          var point = new Point();
          point.UsernameGotPoint = originalSong.UserName;
          point.UsernameGavePoint = User.Identity.Name;
          point.Date = DateTime.Now;
          point.Score = 1;
          point.CurrentFavId = id;
          repository.AddPoint(point);
  
          repository.Save();
          return RedirectToAction("Index");
          }
          else return JavaScript(???);
      }
  </code></pre>
  
  <p>here is my jquery Ajax:</p>
  
  <pre><code>  $(".btnAddOtherSongPoints").click(function () {
          var songId = $(this).attr("name");
  
          $.ajax({
              beforeSend: function () { ShowAjaxLoader(); },
              url: "/Home/AddPointAndCopyOtherSongToPlaylist/",
              type: "POST",
              data: { id: songId },
              success: function () { HideAjaxLoader(), ShowMsg("Song Added Successfully") },
              error: function () { HideAjaxLoader(), ShowMsg("Song could not be added, please try again") }
          });
      });
  </code></pre>
  
  <p>based on whether he was not allowed to give as point in the success part of my ajax request I want to display a different message so i'm guessing I would need an if statement in there to check whether the data object is not null (that means the server returned something, in this case a javascript function or something like that)</p>