Using ajax: MVC3 Share DropDownList or Hidden value with multiple forms on newest questions tagged ajax – Stack Overflow

I have a jQuery dialog that holds multiple tabs, each tab contains a form, and the jQuery dialog contains a DropDownList with a “global” value that will be shared across all the tabs/forms.

The key is “Site”, which is set either by a hidden field or by a drop down list depending on the result from the controller.

This is probably a very trivial task but I can’t figure out how to do it (Still new to MVC3, JavaScript and web programming in general). I could grab the value in JavaScript by doing var value = $('#Site').val(); but I don’t know how to send it to the controller since I can’t save JS variables in C# variables but only vice versa. I use this command to submit the form: $('#' + tabid).submit();

Code:

<div id='jquery-dialog' title="Create new">

  @if (ViewBag.SiteList == null)
  {
    @Html.Hidden("Site", Request.Params["ForSite"])
  }
  else
  {
    @Html.DropDownList("Site", (SelectList)ViewBag.SiteList)
  }

  <div id="tabs">
    <ul>
      <li><a href="#tab0">Tab 0</a></li>
      <li><a href="#tab1">Tab 1</a></li>
    </ul>

    @using (Ajax.BeginForm("Create", null, new AjaxOptions() { HttpMethod = "POST" }, new { id = "tab0" }))
    {
      <div id="tab0">
        This is Tab 0
      </div>
    }

    @using (Ajax.BeginForm("Create", null, new AjaxOptions() { HttpMethod = "POST" }, new { id = "tab1" }))
    {
      <div id="tab1">
        This is Tab 1
      </div>
    }
  </div>
</div>

See Answers


source: http://stackoverflow.com/questions/11736794/mvc3-share-dropdownlist-or-hidden-value-with-multiple-forms
Using ajax: using-ajax



online applications demo