title: How can I Pass String from MVC to Javascript to Execute using Ajax
body: <pre><code>  public ActionResult GiveTicket(Guid voteId, Guid applyId,string cptcha)
      {       
          //檢查此票選是否允許此登入方式
          var canVoteWay = _voteService.GetVoteWay(voteId);
  
          string message = string.Empty;
          string loginPath = $"{ConfigurationManager.AppSettings["DomainName"]}/Account/Login?returnUrl={Request.UrlReferrer}";
  
          //檢查是否已登入
          if (User.Identity.IsAuthenticated &amp;&amp; WebLogic.HasValue(canVoteWay, (int)CurrentUser.LoginType))
          {               
              // [驗證圖形驗證碼]
              if (string.IsNullOrEmpty(cptcha) || cptcha != Session["VerificationCode"]?.ToString())
              {
                  Response.Write("&lt;script language=javascript&gt; bootbox.alert('圖形驗證碼驗證錯誤，請重新輸入!!')&lt;/script&gt;");
                  return null;
              }
  
              //var result = _voteService.GiveTicket(voteId, applyId, CurrentUser.Id, CurrentUser.LoginType);
              Response.Write("&lt;script language=javascript&gt; bootbox.alert('投票成功')&lt;/script&gt;");
              return null;              
          }
  
  
          message = _voteService.VoteWayString(canVoteWay, "請先登入，才能參與投票!! 投票允許登入的方式:");
          Response.Write("&lt;script language=javascript&gt; if (confirm('" + message + "',callback:function(){})){window.location = '" + loginPath + "'}&lt;/script&gt;");
          return null;
      }     
  </code></pre>
  
  <blockquote>
    <p>My ajax code</p>
  </blockquote>
  
  <pre><code> function GiveTicket(applyId) {
          var voteId = $('input[name="Id"]').val();
          var captcha = $('input[name="Captcha"]').val();
          $.ajax({
              url: '@Url.Action("GiveTicket", "Vote")',
              data: { applyId: applyId, voteId: voteId, cptcha: captcha },
              type: 'Get',
              success: function (data) {
                  console.log(data);
  
                  //bootbox.alert(data);
              }
          });
      }
  </code></pre>
  
  <p>Like you see. I have many condition. SomeTime I need to pass alert or confirm to 
  web client . when I pass confirm. if user click Yes. I need to redirect Url.
  So that I decide to write string to web client.</p>
  
  <p>The problem is How I can just execute string from MVC like alert,confirm...</p>