title: Update ViewBag Data on MVC Razor View page using JSON Data JQuery
body: <p>I am trying to update the ViewBag on MVC Razor view page using JSON data. But it is not updating the ViewBag or Div. When I am looking the alert on my success, it is showing the updated values but inside the page, it is not changing the value. Initially when page is loading, it is showing the values. </p>
  
  <p>My JQuery code is -</p>
  
  <pre><code>$(document).ready(function ()
      {
          $('#ddl2').change(function (e)
          {
              e.preventDefault();
              var str_test = $("#v_ddl2 :selected").text();           
              var data1 = {str_test: str_test }; 
              var url = '@Url.Action("ddl_2")?id=' + id;
  
              $.post(url, data1, function (data)
              {
                  $('#nav_div').html(data);
                  alert(JSON.stringify(data)); // ALERT showing the updated data
              });
  
          });
      });
  </code></pre>
  
  <p>Controller - </p>
  
  <pre><code>public JsonResult ddl_2(string str_test)
      {
          GetDat(str_test);
  
          return Json(new { success = true, ViewBag.str_display });
      }
  </code></pre>
  
  <p>HTML -</p>
  
  <pre><code>&lt;div id='#nav_div'&gt;@ViewBag.str_display&lt;/div&gt;
  </code></pre>
  
  <p>Could someone please help me how ViewBag or Div will show the updated data. </p>
  
  <p>Thanks</p>