2017-04-10 53 views
0

我需要將contentType作爲「application/json」發送到webApi控制器。下面是我使用的代碼,它不工作。將內容類型從kenod下拉列表發送到webapi

@(Html.Kendo().DropDownList() 
            .Name("ddlPatientClass").AutoBind(true) 
            .HtmlAttributes(new { style = "width: 67px!important;" }) 
            .DataTextField("ModuleName") 
            .DataValueField("RoleId") 
            .ContentType("application/json")   
            .DataSource(source => 
            { 
             source.Read(read => read.Url(Url.HttpRouteUrl("DefaultApi", new { controller = "MedicalVisit", Action = "GetPatientClass" })).Type(HttpVerbs.Get));//.Type(HttpVerbs.Get).Data("ModuleParamCP")); 
            }) 
           ) 
+0

請問你的控制器看起來 –

回答

0

而不是@Html輔助類,你可以使用下面的劍道UI JQyery下拉列表如下綁定JSON數據。

HTML

<input id="ddlPatientClass" name="ddlPatientClass" class="custom-select" style="width: 100%;" /> 

JQuery的

$(document).ready(function() { 

      var data = [ 
          { text: "0", value: "0" }, 
          { text: "10", value: "10" }, 
          { text: "25", value: "25" }, 
          { text: "30", value: "30" },       
          { text: "100", value: "100" } 
         ]; 
    // This data you can get from WebApi - using Ajax call 

    // After get JSON data from webApi - you can create DropDownList as below 


      $("#ddlPatientClass").kendoDropDownList({ 
       dataTextField: "text", 
       dataValueField: "value", 
       dataSource: data, 
       index: 0, 
       optionLabel: "-- Choose % --", 
      }); 
}); 
+0

我的問題是如何能夠用我的劍道下拉列表中的contentType值發送至AP ControllerMethod。就像在ajax中一樣,我們使用contentType:「application/json」,就像我需要將contentType傳遞給api一樣 –