title: How to bind the dropdownlist in MVC WebAPI?
body: <p>I am trying to bind dropdown values in razor view from webapi controller. But, why is it not accepting the view in my webapi. whether the view() accepts only in the controller not the apicontroller? I am getting an error in View(model) saying "method, delegate or event is expected".</p>
  
  <p>Basically, I am trying to change the logic. Earlier, I was sending ajax request to web api to get the values for drop down. Now, I  don't want to use that. I feel sending an ajax request is not a better approach to load the drop down values. Now, I want to remove ajax call logic and load the drop down values from the web abi controller in razor dropdown (select) control.</p>
  
  <p>CS HTML:</p>
  
  <pre><code> &lt;select id="sltCustomers" name="sltCustomers"&gt;&lt;/select&gt;
  </code></pre>
  
  <p>JQuery:</p>
  
  <pre><code>$(document).ready(function () {
              var planCodes = $('#sltCustomers');
  
              $.ajax({
                  url: '/api/ClearCache/Customers',
                  type: "Get",
                  success: function(data) {
                      for (var i = 0; i &lt; data.length; i++) {
                          var option = $("&lt;option/&gt;");
                          option.attr("value", data[i]).text(data[i]);
                          planCodes.append(option);
                      }
                  },
                  error: function(msg) { alert(msg); }
              });
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>public IEnumerable&lt;String&gt; GetAllCustomers()
      {
          var customerEntities = new CustomerEntities();
          return customerEntities.Customers.Select(c =&gt; c.CustomerName);
      }
  </code></pre>
  
  <p>Web Api controller method:</p>
  
  <pre><code>     //GET api/ClearCache/Customers
      [System.Web.Http.HttpGet]
      public IEnumerable&lt;String&gt; GetCustomers()
      {
          return _clearCache.GetAllCustomers();
      }
  </code></pre>
  
  <p>Now, I am trying to move the above logic to controller. I don't want to send ajax request just for loading values.</p>
  
  <p>View Model:</p>
  
  <pre><code>public class CustomerViewModel
  {
      [Display(Name = "Name")]
      public IEnumerable&lt;String&gt; Customers { get; set; }
  }
  </code></pre>
  
  <p>Web api method:</p>
  
  <pre><code> public ActionResult Customers()
   {
      var model = new CustomerViewModel
      {
          Customers = _clearCache.GetAllCustomers()
      };
  
      return View(model);
   }
  </code></pre>