Anele Ngqandu

Anele Ngqandu

  • 1.3k
  • 430
  • 28.6k

How to fix my search using a select that is populated razor

Apr 22 2019 12:44 PM
A select populated using razor
  1. <select placeholder="Select campus" id="selCampus" class="form-control" required>    
  2.                                 <option value="">Select campus</option>    
  3.     
  4.                                 @foreach (var campus in Model.Campuses)    
  5.                                 {    
  6.     
  7.                                     <option value="@campus.Id">@campus.CampusName</option>    
  8.     
  9.                                     }    
  10.                                 </select>  
Onchange for the select pointing to the action controller 
  1. $("#selCampus").change(function () {  
  2.                 //$(".employee").remove();  
  3.                 $.ajax({  
  4.                     type: 'POST',  
  5.                     url: '/admin/staff/',  
  6.                     dataType: 'html',  
  7.                     data: ({  
  8.                         campusId: $(this).val()  
  9.                     }),  
  10.                     success: function () {  
  11.                     }  
  12.                 });  
  13.             });  
ActionResult, this loads on pageload and onchange of the select
 
  1. public ActionResult Employees(long? campusId)  
  2.                 {  
  3.                     var client = new RestClient(Request.Url.GetLeftPart(UriPartial.Authority).ToString());  
  4.                     var request = new RestRequest("api/employee/getClinicMembers/{campusId}", Method.POST);  
  5.                     request.AddParameter("campusId", campusId, ParameterType.QueryString);  
  6.   
  7.                     var result = client.Execute(request);  
  8.   
  9.                     ViewBag.title = "Home | Members";  
  10.                     return View(result.Data);  
  11.                 }  
Does not want to redraw this code with new data, Even tho Model.Employees has filtered data
  1. @foreach (var member in Model.Employees)    
  2.                         {    
  3.                             <div class="col-lg-4 col-xlg-3 col-md-5 employee">    
  4.                                 <div class="card">    
  5.                                     <div class="card-body">    
  6.     
  7.                                     </div>    
  8.                                 </div>    
  9.     
  10.     
  11.                             </div>    
  12.     
  13.                         }

Answers (2)