title: ASP.NET MVC3 passing data between primary view and a search view via Ajax link
body: <p>I have just started learning ASP.NET MVC3.</p>
  
  <p>I have the following scenario. In a create view for a certain model the user can lookup code/description by clicking on a link (rendered with Html.ActionLink helpers).  The lookup values are retrieved from lookup tables in a database and presented in a separate view. The two views are handled by two different controllers.  When the user selects a lookup value in the latter view that value (code+description) should be copied back to the create view.</p>
  
  <p>How can data be passed between the two views? Is this not possible due to the stateless nature of Http requests?</p>
  
  <p>I tried that with an Ajax link, but it didn't worked out.</p>
  
  <p>code snippet Create view:</p>
  
  <pre><code>&lt;fieldset&gt;
      &lt;legend&gt;Z-Info&lt;/legend&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.ZZL_U_CODE)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.ZZL_U_CODE)
          @Html.ValidationMessageFor(model =&gt; model.ZZL_U_CODE)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Ajax.ActionLink("Land code test", "Index", "Domein", new {name = "lan" }, 
              new AjaxOptions {
                  HttpMethod = "Get",
                  Url = Url.Action("Index", "Domein", new {name = "lan" }), 
                  OnBegin = "OnBegin",
                  OnSuccess = "InsertCodeNaam",
                  OnFailure = "OnFailure",
                  OnComplete = "OnComplete"
              })
      &lt;/div&gt;
  </code></pre>
  
  <p>When the user select a code/description the following <code>Select</code> action is called which returns <code>Json</code> data back.</p>
  
  <p>Select action:</p>
  
  <pre><code>public class DomeinController : Controller
  {
      private ZZLEntities db = new ZZLEntities();
  
      //
      // GET: /Domein/
  
      public ViewResult Index(string name)
      {
          DomeinViewModel model = DomeinRepositry.GetAll(name);
          return View(model);
      }
  
  
  
       GET: /Domein/Select/5
  
      public JsonResult Select(int id, string naam)
      {
          return Json(new DomCodeNaam { codeValue = id, naamValue = naam }, JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  
  <p>Are there other solutions possible? Can partial views be an option? </p>