2016-10-11 9 views
0

入力に何も表示されません。選択にデータが表示されません

これが私の見解で私のスクリプト機能である:私はデータを表示したい

<script> 
var Caracteristicas = []; 

function LoadCaracteristicas(element) { 
    if(Caracteristicas.length === 0) 
    { 
     $.ajax({ 
      url:'@Url.Action("GetCaracteristicas","Inspeccion")', 
      type: 'GET', 
      cache: false, 
      dataType: 'json', 
      success: function(data){ 
       Caracteristicas = data; 
       alert(data); 
       renderCaracteristica(element) 
      }, 
      error: function (e) { 
       console.log(e) 
      } 
     }); 
    } 
    else 
    { 
     renderCaracteristica(element); 
    } 
} 

function renderCaracteristica(element) { 
    var $ele = $(element); 
    $ele.empty(); 
    $ele.append($('<option/>').val('0').text('Select')); 
    $.each(Caracteristicas, function (i, val) { 
     $ele.append($('<option/>').val(val.Id_Caracteristica).text(val.Descripcion)); 
    }) 
} 

マイセレクト:

<table class="table table-responsive"> 
    <tr> 
     <td>Caracteristica</td> 
     <td>Resultado</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr class="mycontainer" id="mainrowCateristica"> 
     <td> 
      <select id="IDCateristicas" class="form-control"> ----- Show Data 
       <option>Select</option> 
      </select> 
      <span class="error">Seleccione una Caracteristica</span> 
     </td> 
     <td> 

       <input type="radio" id="RadioOK" name="resultado" value="1"> OK<br> 
       <input type="radio" id="RadioNOK" name="resultado" value="0"> NOK<br> 
     </td> 
     <td> 
      <input type="button" id="BtnAdd" value="Agregar" style="width:80px" class="btn btn-success" /> 
     </td> 
    </tr> 
</table> 

私のコントローラ機能:

public JsonResult GetCaracteristicas() 
    { 
     CalidadEntities db = new CalidadEntities(); 
     var data = from c in db.Caracteristicas select c; 
     return Json(data.ToList(), JsonRequestBehavior.AllowGet); 
    } 

Th電子コントローラは、関数JsonResultでデータを渡すと仮定しますが、selectではanythibgを表示しません。初めに私の見解では

<script type="text/javascript"> 
      window.onload = function() { 
       LoadCaracteristicas($("#IDCateristicas")); 
      }; 

+0

「アラート(データ)」には何が表示されますか? – adeneo

+0

GetCaracteristicas()関数は任意の値を返しますか? from C# –

+0

'LoadCaracteristicas()'を呼び出す場所が見つかりませんでした。この電話がありますか? –

答えて

0

は最後に、私はそれを取得します。私がいない理由が、その唯一の方法は、それは私のために働くん

public JsonResult GetCaracteristicas() 
    { 
     int tipoc = 10; -- Temporaly 
     CalidadEntities db = new CalidadEntities(); 
     var data = (from c in db.Caracteristicas where c.Id_TComponente == tipoc 
        select new { 
         Id_Caracteristica =c.Id_Caracteristica, 
         Descripcion = c.Descripcion 
        }).ToList(); 
     return Json(data, JsonRequestBehavior.AllowGet); 
    } 

:私は私のコントローラの私の機能を変更します。全てに感謝。

関連する問題