title: MVC - Posting json results to the controller and then redirecting from the controller
body: <p>Being new to MVC and knockout, I need a little help.  I am trying to get some JSON results(as a string) posted to my controller and then have the controller RedirectToAction to a new view and action.</p>
  
  <p>PROBLEM: The controller always returns to same view even if a RedirectToAction is hit. </p>
  
  <p>(It goes through the redirect code and then at the end goes right on back to the posting view.)  I have had to put in place a "Next" action and it is a little embarrassing.</p>
  
  <p>ALSO: Is a hidden field the best way to store/pass ids when doing the post?</p>
  
  <p>VIEW</p>
  
  <pre><code>@model WebRole.Website.Models.Registration3Model
  @{
  ViewBag.Title = "Step 3: Adding Members";
  }
  @using (Html.BeginForm())
  {
  
  &lt;input name="GroupID" id="GroupID" type="hidden" value="@ViewData["GroupID"]" /&gt;      
  &lt;div id="Div1"&gt;
      &lt;div class="5grid-layout"&gt;
          &lt;div class="row"&gt;
              &lt;div class="8u mobileUI-main-content"&gt;
                  &lt;!-- Content --&gt;
                  &lt;div id="content"&gt;
                      &lt;br /&gt;
                      &lt;!-- Article --&gt;
                      &lt;article class="featured"&gt;
                          &lt;header&gt;
                              &lt;h2&gt;Registration&lt;/h2&gt;
                              &lt;span class="byline"&gt;&lt;/span&gt;
                          &lt;/header&gt;
                      &lt;/article&gt;
                      &lt;!-- Section --&gt;
                      &lt;div class="5grid grid-spaced"&gt;
                          &lt;div class="row"&gt;
                              &lt;section class="do-6u"&gt;
                                  &lt;h2&gt;Step 3.&lt;/h2&gt;
                                  &lt;p&gt;
                                      You can add members to your group/family by selecting how the members will be notified (ex. Email, Cellphone) and the address/phone # of the member.
                                  &lt;/p&gt;
                                  &lt;p /&gt;
                                      &lt;div id='contactsList'&gt;
                                          &lt;table class='contactsEditor'&gt;
                                              &lt;tbody data-bind="foreach: contacts"&gt;
                                                  &lt;tr&gt;
                                                      &lt;td&gt;
                                                          &lt;input type="radio" value="Email" data-bind="checked: contactType" /&gt;E-mail
                                                          &lt;input type="radio" value="Voice" data-bind="checked: contactType" /&gt;Voice
                                                          &lt;input type="radio" value="SMS" data-bind="checked: contactType" /&gt;SMS
                                                      &lt;/td&gt;
                                                      &lt;td&gt;
                                                          &lt;input data-bind='value: contactValue' size="40" /&gt;
  
                                                          &lt;a href='#' data-bind='click: $root.removeContact'&gt;Remove&lt;/a&gt;
                                                      &lt;/td&gt;               
                                                  &lt;/tr&gt;
                                              &lt;/tbody&gt;
                                          &lt;/table&gt;
                                          &lt;input type="hidden" data-bind='value: lastSavedJson' /&gt;
                                          &lt;a href='#' data-bind='click: addContact'&gt;Add &lt;/a&gt;
                                      &lt;/div&gt;
                                  &lt;p /&gt;
                                  &lt;p&gt;
                                      &lt;button name="button" value="AddNewMember" data-bind='click: save, enable: contacts().length &gt; 0'&gt;Invite&lt;/button&gt;
  
                                      &lt;button name="button" value="Next"&gt;Finish&lt;/button&gt;
                                  &lt;/p&gt;
                              &lt;/section&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  }
      &lt;script type="text/javascript"&gt;
          var initialData = [
          {
              contactValue: "",
              contactType: ""
          }
      ];
  
      var ContactsModel = function (contacts) {
          var self = this;
          self.contacts = ko.observableArray(ko.utils.arrayMap(contacts, function (contact) {
              return { contactValue: contact.firstName, contactType: contact.contactType };
          }));
  
          self.addContact = function () {
              self.contacts.push({
                  contactValue: "",
                  contactType: ""
              });
          };
  
          self.removeContact = function (contact) {
              self.contacts.remove(contact);
          };
  
          self.save = function () {
              self.lastSavedJson(JSON.stringify(ko.toJS(self.contacts), null, 2));
              var s = document.getElementById("GroupID").value
              $.ajax({
                  url: "/Home/Add/",
                  type: "POST",
                  data: { jsonString: JSON.stringify(ko.toJS(self.contacts)), groupID: s },
                  success: function (result) {
                  },
                  error: function (jqXHR, textStatus, errorThrown) {
                      var errorMessage = '';
                      $('#message').html(jqXHR.responseText);
                  }
              });
  
          }; 
  
  
          self.lastSavedJson = ko.observable("")
      };
  
      ko.applyBindings(new ContactsModel(initialData));
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>MODEL:</p>
  
  <pre><code>public class Registration3Model
  {
      public string GroupID { get; set; }
  
      // Success Message
      public string SuccessMessage { get; set; }
  
      public string jsonString { get; set; }
  }
  
  public class Registration4Model
  {
      public string GroupID { get; set; }
  
      public Group SelectedGroup { get; set; }
  
      public Person Owner { get; set; }
  
      public List&lt;ContactInfo&gt; GroupContacts { get; set; }
  
      // Success Message
      public string SuccessMessage { get; set; }
  }
  </code></pre>
  
  <p>CONTROLLER:</p>
  
  <pre><code>public class HomeController : Controller
  {
      public class JsonCatch
      {
          public string groupID { get; set; }
          public string contactType { get; set; }
          public string contactValue { get; set; }
      }
  
  
      [AllowAnonymous]
      public ActionResult Registration3(Registration3Model model)
      {
          ViewData["GroupID"] = model.GroupID;
          return View("Registration3",  model);
      }
  
      [HttpPost]
      [ActionName("Add")]
      [AllowAnonymous]
      [AcceptVerbs(HttpVerbs.Post)]
      public ActionResult Add(string jsonString, string GroupID)
      {
  
      string s =GroupID;
  
          List&lt;JsonCatch&gt; j = JsonConvert.DeserializeObject&lt;List&lt;JsonCatch&gt;&gt;(jsonString);
          foreach (JsonCatch c in j)
          { 
              if (s != "")
              {
  
                  // for member 1
                  // 1. Add Person
                  Person p = new Person();
                  p.LastName = "";
                  p.FirstName = "";
                  p.PersonID = Guid.NewGuid();
                  p.RowKey = p.PersonID.ToString();
                  p.PartitionKey = "";
                  p.Image = string.Format("../../Assets/Images/People/pic{0}.png", new Random().Next(1, 12));
                  this.GetContext().InsertPerson(p);
  
                  // 2. Add GroupMember
                  GroupMember gm = new GroupMember();
                  gm.RowKey = p.RowKey.ToString();
                  gm.PartitionKey = s;
                  gm.GroupMemberID = Guid.NewGuid();
                  gm.TrustLevel = "Readonly";
                  this.GetContext().InsertGroupMember(gm);
  
                  // 3. Add ContactInfo
                  ContactInfo ci = new ContactInfo();
                  ci.PartitionKey = p.RowKey;
                  ci.ContactInfoID = Guid.NewGuid();
                  ci.RowKey = ci.ContactInfoID.ToString();
                  ci.Type = c.contactType;
                  ci.Value = c.contactValue;
                  ci.UseToNotify = true;
                  this.GetContext().InsertContactInfo(ci);
  
                  // 4. Add Notification
                  Notification n = new Notification();
                  n.PartitionKey = "Invitation";
                  n.NotificationID = Guid.NewGuid();
                  n.RowKey = n.NotificationID.ToString();
                  n.ContactType = c.contactType;
                  n.ContactInfoValue = c.contactValue;
                  n.NotificationType = "Invitation";
                  n.PersonRowKey = p.RowKey;
                  n.GroupRowKey = s;
                  this.GetContext().InsertNotification(n);
              }
              }
          return View("Registration4", new { GroupID = s });
      }
  
              [AllowAnonymous]
      public ActionResult Registration4(Registration4Model model)
      {
          model.SelectedGroup = this.GetContext().GetGroup(model.GroupID);
          model.GroupContacts = model.SelectedGroup.GetContactInfoes(this.GetContext());
          model.Owner = model.SelectedGroup.GetOwner(this.GetContext());
  
          return View(model);
      }
  
              [HttpPost]
      [AllowAnonymous]
      [AcceptVerbs(HttpVerbs.Post)]
      [ActionName("Registration3")]
      [AcceptParameter(Name = "button", Value = "Next")]
      public ActionResult Registration3_Next(Registration4Model model)
      {
          return RedirectToAction("Registration4", new { GroupID = model.GroupID });
      }
  
  
      [HttpPost]
      [AllowAnonymous]
      [AcceptVerbs(HttpVerbs.Post)]
      [ActionName("Registration4")]
      [AcceptParameter(Name = "button", Value = "Continue")]
      public ActionResult Registration4_Continue(Registration4Model model)
      {
          return Redirect("~/AnotherWebsite.aspx");
      }
  
      #endregion
  }
  
  public class AcceptParameterAttribute : ActionMethodSelectorAttribute
  {
      public string Name { get; set; }
      public string Value { get; set; }
  
      public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
      {
          var req = controllerContext.RequestContext.HttpContext.Request;
          return req.Form[this.Name] == this.Value;
      }
  }
  </code></pre>