title: Update ViewBag with jQuery and rendering results
body: <p>I have an MVC3 application which uses ViewBag variables to dynamically fetch data from database and dynamically generate the interface.</p>
  
  <p>I am using jQuery to call action method to insert some values to the database and update a ViewBag variable accordingly. I want to refresh the div with the new ViewBag values returned after the update from server...Cant really figure how to do that. Thanks</p>
  
  <p>This is my View code:</p>
  
  <pre><code>    &lt;div id="phys"&gt;
          &lt;fieldset&gt;
              &lt;legend&gt;IPSS&lt;/legend&gt;
  
  
                  @foreach (var parameter in ViewBag.four.Parameters)
                  {
  
                      @MyHelpers.ParameterList(parameter, ViewBag.four.ParametersValues, "ParametersList")
  
  
                  }
                  &lt;button type="button" onclick="print()" class="t-button"&gt;
          Add Physician&lt;/button&gt;
  
          &lt;table&gt;
      &lt;thead&gt;
          &lt;th&gt;
              Physician
          &lt;/th&gt;
          &lt;th&gt;
              Time
          &lt;/th&gt;
          &lt;th&gt;
              Delete
          &lt;/th&gt;
  
  
      &lt;/thead&gt;
  
      &lt;tbody&gt;
          @foreach (var row in ViewBag.physicians.ParametersValues)
          {
              &lt;tr&gt;
                  @{var items = ((string)row.Value).Split('|');}
  
                  &lt;td&gt;@items[0]
                  &lt;/td&gt;
                  &lt;td&gt;@items[1]
                  &lt;/td&gt;
                  &lt;td&gt;@Html.ActionLink("Delete", "DeleteVisitParameter", new { vpid = @row.VisitParameterID })&lt;/td&gt;
  
              &lt;/tr&gt;
          }
      &lt;/tbody&gt;
  
  &lt;/table&gt;
  
          &lt;/fieldset&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p><strong>This is my jQuery:</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function () {
  
          print = function () {
  
              //$.post("/visit/physicians", { phy: $("#ParamList7 option:selected").text(), vID: '@ViewBag.VisitID' })
  
              $.ajax({
                  cache: false,
                  type: "POST",
                  url: '@Url.Content("~/visit/physicians")',
  
  
                  data: { phy: $("#ParamList7 option:selected").text(), vID: '@ViewBag.VisitID' },
                  success: function (data) {
  
                      //What Shall I do here to update div #phys with new View Data??
                  },
                  fail: function (msg) {
                      alert("Fail"); ;
                  }
              });
  
  
  
          };
  
  
      });
  
  &lt;/script&gt;
  </code></pre>