title: C# & AJAX- Update view with new model
body: <p>I have a .NET web app that simply works in this way: <strong>Page A</strong> where I send an input (barcode scan result) and then it goes to <strong>Page B</strong> to load a table created by many queries and inserted results in a view model.</p>
  
  <p>What I want to do is that when I go to scan another barcode while I am in Page B, it has to do the same operation that it does with Page A: Page B with new results. It means that through AJAX I send a parameter to the controller, it makes his queries and operations and then it has to return a View with the new View Model and reload the page. Problem it is that it doesn't reload the page with new View Model, but it stays with the old data. </p>
  
  <p>I also tried putting the table in a partial view and try to make it reload after every input in Page B, but it doesn't load all the javascript code in the page which is the most important thing I need to keep (editing table values etc..). Javascript code is contained in Page B, not in partial view ".cshtml". </p>
  
  <p>AJAX CODE: I send an ID to the controller, and it returns an HTML which I put on the ID of a div containing the partial view of the table.</p>
  
  <pre><code>                    $.ajax
                      ({
                          type: 'POST',
                          url: '@Url.Action("QueryBollaTestP", "Bolla")',
                          data: JSON.stringify({ 'NumBolla': evt.state.code }),
                          contentType: 'application/json; charset=UTF-8',
                          dataType: "html",
                      success: function (data)
                      {
                        $(".tesst").html(data);
                      },
                  })
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>[HttpPost]
  public ActionResult QueryBollaTestP(string NumBolla){
  ......... all operations and queries..... going to pickingViewModel for the table
  return PartialView("_BollaTable", pickingViewModel);
  }
  </code></pre>
  
  <p>Is there anything for that? Doesn't matter if it is with the use of partial view or not, important is it will update the model of the page with the correct data and then it loads the javascript code.</p>