title: Passing Model from view to controller using Jquery Ajax
body: <p>I want to pass my ViewModel from View to the Controller for this i am using Ajax and my code is as follows in which i have to show the alert box and i am getting an error as
  "Invalid JSON primitive: info."</p>
  
  <p>Controller:</p>
  
  <pre><code>[HttpPost]
          public JsonResult Test(OData.FtpAccount info) {
              try {
                  string FileName = Utils.File.TempName + ".txt";
  
                  FtpClient ftp = GetClient(info);
  
                  UnicodeEncoding uni = new UnicodeEncoding();
                  byte[] guid = uni.GetBytes(Utils.File.TempName);
  
                  FileName = info.Root + (info.Root.EndsWith("/") ? "" : "/") + FileName;
                  ftp.Upload(GetTempFile(guid),FileName); //Upload File to Ftp in FtpPath Directory.
  
                  string url = info.GetHttpUrl(FileName);
                  byte[] result = Utils.Web.ReadByte(new System.Uri(url));
  
                  ftp.FtpDelete(FileName);
  
                  if (uni.GetString(result) == uni.GetString(guid)) {
                      return Json(new{ success=true});
                  } else {
                      return Json(new { warning = true, message = "Warning : Test Upload worked, Test Delete Worked, Http Access of File did not return same content as uploaded." }); 
                  }
              } catch (System.Exception ex) {
                  return Json(new { error = true, message = "Ftp Test Failed : " + ex.Message });
              }
          }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@model VZDev.ViewModels.FtpAccountViewModel
  @{
      ViewBag.Title = "Watch";
      var val = Json.Encode(Model);
  
  }
  &lt;div class="control-group"&gt;
          &lt;div class="controls"&gt;
              &lt;button type="button" class="btn" id="test"&gt;&lt;i class="icon-test"&gt;&lt;/i&gt; Test&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
  }
  &lt;script type="text/javascript"&gt;
      $(function () {
          $("#test").click(function () {
              var check=@Html.Raw(val);
              $.ajax({
                  type: 'post',
                  url: rootURL + 'Ftp/Test',
                  data: {info:JSON.stringify(check)},
                  contentType: 'application/json; charset=utf-8',
                  dataType: "json",
                  success: function (data) {
                      alert(data);
                  }
              });
          });
      });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Model:</p>
  
  <p>public partial class FtpAccount
      {</p>
  
  <pre><code>    [DataMember(Order = 1)]
      [ScaffoldColumn(false),DatabaseGenerated(DatabaseGeneratedOption.Identity),Key,UIHint("Id"),Display(Name="Id")]
      [Column("ID")]
      public long ID{get;set;}
  
      [DataMember(Order = 2)]
      [UIHint("Service Provider"),Display(Name="Service Provider"),Required(ErrorMessage="Service Provider is required"),StringLength(100)]
      [Column("ServiceProvider")]
      public string ServiceProvider{get;set;}
  
      [DataMember(Order = 3)]
      [UIHint("Ftp Path"),Display(Name="Ftp Path"),Required(ErrorMessage="Ftp Path is required"),StringLength(500)]
      [Column("FtpPath")]
      public string FtpPath{get;set;}
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>now here i want to pass my ViewModel from view to controller.
  Thanks in Advance!!!</p>