title: Showing items in the same page after selecting from a dropdown control
body: <p>I have a controller with an <code>Index</code> action which returns a <code>ViewModel</code> and a <code>GetCategories</code> action which should return a partial view.</p>
  
  <p>So here is my <code>CategoryController.cs</code> file:</p>
  
  <pre><code>public class CategoryController : Controller
      {
          public ActionResult Index()
          {
              CategoryViewModel ob = new CategoryViewModel();
              ob.LoadLanguages();
              return View(ob);
          }
  
  
  
          public ActionResult GetCategories(int langID)
          {
              CategoryViewModel ol = new CategoryViewModel();
              ol.LoadCategoriesByLanguage(langID);
              if (Request.IsAjaxRequest())
                             return PartialView("GetCategories",ol);
  </code></pre>
  
  <p>In my <code>Index.cshtml</code> view I create a dropdown list and, when the user selects an element, it makes an Ajax request to the <code>getCategories</code> action and on success I should load the <code>GetCategories</code> partial view. The problem is that it redirects me to a new page and I can no longer see my dropdown. </p>
  
  <p>Here is my <code>Index.cshtml</code> file:</p>
  
  <pre><code>@model Onion.Web.ViewModels.CategoryViewModel
  
  &lt;script&gt;
      $(document).ready(function () {
          $("#ddlLanguages").change(function () {
              $.ajax({
                  type: 'GET',
                  url: '@Url.Action("GetCategories")' + '?langId=' + this.value,
                  data: {},
                  success: callbackFuntion('@Url.Action("GetCategories")' + '?langId=' + this.value),
                  error: function () { alert('Error'); }
              });
          });
  
      });
  
      function callbackFuntion(url){
  
          window.location = url;
      }
  &lt;/script&gt;
  @Html.DropDownList("Languages", new SelectList(Model.lstLanguages, "LanguageID", "Name"), "SELCT  LANGUAGE-----&gt;",new { id = "ddlLanguages" })
  
              } 
  </code></pre>
  
  <p>And here is my <code>Category.cshtml</code> file:</p>
  
  <pre><code>@model Onion.Web.ViewModels.CategoryViewModel
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;ID&lt;/td&gt;
          &lt;td&gt;Title&lt;/td&gt;
  
      &lt;/tr&gt;
      @foreach (var item in Model.lstCategoryLanguages)
      {
          &lt;tr&gt;
              &lt;td&gt;@item.Title&lt;/td&gt;
              &lt;td&gt;@item.ShortDescription&lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  
  
  I can't beleve how easy it is in web forms and here i'm struggling for hours. Is there a better way to do all this. Thank you in advance
  </code></pre>