logo
down
shadow

Populate Dropdown in View from another Controller


Populate Dropdown in View from another Controller

By : Axel
Date : November 20 2020, 03:01 PM
wish of those help I understand your desire to farm out certain tasks to dedicated classes. However, I think you are overthinking this a little bit.
I'm not 100% sure what that error is actually telling you in terms of your code, but it seems like you've probably got some wonky view returns because your setting the ViewBag information within a different controller than the one that returns the view. Am I understanding that part of it correctly?
code :
ViewBag.DropDownDeviceType= *wherever-your-static-method-is*.PopulateDeviceType(model.DeviceTypeID);


Share : facebook icon twitter icon
Populate a dropdown in word from column in excel and then on dropdown change populate textboxes with related field (VBA)

Populate a dropdown in word from column in excel and then on dropdown change populate textboxes with related field (VBA)


By : Marissa Nicholas
Date : March 29 2020, 07:55 AM
How to Populate dropdown in view Page?

How to Populate dropdown in view Page?


By : Masih
Date : March 29 2020, 07:55 AM
will be helpful for those in need Just fetch the JSON data from the controller with your ajax request, filter that json data and collect in a javascript variable and pass it in your defined sub category in same view.
Hope this makes sense:
code :
// Send only JSON data on request 
function ajax(){
      $id = $_POST['id'];
      // print_r($id);
      $this->load->model('admin_model');
      $query =$this->admin_model->get_sub_details($id);
      $result = $query->result_array();

      // Send Data only in JSON Format
      $this->output
               ->set_content_type("application/json")
               ->set_output(json_encode(array('data'=>$result)));
    } 
<select name="sub_category" id="sub_category"></select>
//send ajax request to get the JSON data for Categories
$.ajax({
    type : "POST",
    url :"/admin/ajax", 
    dataType: 'json', 
    data :{id:id},
    success:function(response){
       var _option = '';
       // Filter JSON data and Collect in Option
       $.each(resonse.data, function(i, data) {
           _option += '<option value="'+data.s_id+'">'+data.s_name+'</option>';
       });

       // Add Options to Sub Category
       $('#sub_category').html(_option);
    }
});  
AngularJS - Use data returned by a service in the controller and the view to populate dropdown

AngularJS - Use data returned by a service in the controller and the view to populate dropdown


By : Kullapat.T
Date : March 29 2020, 07:55 AM
like below fixes the issue This is my index.html , First you would return the data from your service using the promise:
code :
(function() {
  'use strict';

  var getData = function (fetchDataService) {
      this.getLanguages = function() {

             return fetchDataService.getContent()
              .then(function (returnedData) {
                    return returnedData.data;
                    //console.log(returnedData.data.languages[0]);
                  });
              };   
      };    

      angular.module('assignment3App')
        .service ('getData', ['fetchDataService', getData]);
}());
(function() {
    'use strict';

    //this will be the select value
    $scope.selectedLanguage = '';

    $scope.setLanguage = function(){
        //this is called when the submit button is clicked
        yourService.languageChanged($scope.selectedLanguage);
    };

    var callServ = function (getData) {
        getData.getLanguages().then(function(data){
            //data = returnedData.data
            $scope.languages = data;
        });
    };

    angular.module('assignment3App')
      .controller ('callServ', ['getData', callServ]);      
}());
<select ng-options="language for language in languages"
    ng-model="selectedLanguage">
</select>
<button type="button" ng-click="setLanguage()">Submit</button>
Pass value of form field from view to controller via ajax and populate a dropdown city list based on state selection

Pass value of form field from view to controller via ajax and populate a dropdown city list based on state selection


By : Edwin Kim
Date : March 29 2020, 07:55 AM
will help you Your action method parameter name and the ajax call data parameter name should match. Since your ajax call is sending the selected state value in a parameter called State, you should update your action method to have the same (or the other way)
code :
public JsonResult FillCity2(string state)
{
   //use the state variable in your method now for switch statement
}
success: function (cityArray) { 
    $("#City").html("");
    $.each(cityArray, function (i, city) {
        $("#City").append(
            $('<option></option>').val(city.Value).text(city.Text));
    });
}
Populate a dropdown list via controller action

Populate a dropdown list via controller action


By : user3027145
Date : March 29 2020, 07:55 AM
To fix the issue you can do In a Model-View-Controller (MVC) framework, it is the job of the controller to pass the model to the view. Assuming that your list of strings, items, is correctly populated, the controller needs to pass it to the view.
First, you need to distinguish between actions and helper methods. Actions are public methods in the controller class. Actions can be accessed by the user via URL so in your case, http://application_name/controller_name/PopulateDropDownList would be a valid URL although this is meaningless to the user. Instead, you need to make PopulateDropDownList into a helper method like so:
code :
private async Task<IEnumerable<string>> GetDropdownOptionsList()
{
  List<string> items = ...;
  return items;
}
public async Task<IActionResult> View()
{
  List<string> items = await GetDropdownListOptions();
  return View(items);
}
@model IEnumerable<string>

<select>
  @foreach (string item in Model)
  {
    <option value="@item">@item</option>
  }
</select>
private async void PopulateDropDownList()
{
  List<string> items = ...;
  ViewBag.Items = items;
}
<select>
  @foreach (string item in (IEnumerable<string>)ViewBag.Items)
  {
    <option value="@item">@item</option>
  }
</select>
Related Posts Related Posts :
shadow
Privacy Policy - Terms - Contact Us © voile276.org