2013-01-21 20 views
0

我想在局部視圖使用劍道自動完成自動完成,和我有許多在一個視圖中 因此我必須動態獲取參數,有沒有什麼辦法,我可以得到元素ID的數據粉絲? ?我$(本).VAL(),但它沒有作用:(,我應該用什麼劑量 請幫我:( tihs是我的代碼:多個劍道在Razor視圖

@(Html.Kendo().AutoComplete() 
.Name("Employee" + (string)Session["fileid"]) 
.Placeholder("Employee Name ...") 
.Filter(FilterType.StartsWith) 
.DataSource(source => 
{ 
    source.Read(read => 
       { 
     read.Action(
         "GetEmployeeName", 
         "Proceeds") 
         .Data(
         "function onAdditionalData() {return { text:$(this).val() };}"); 
      }) 
        .ServerFiltering(true); 
}) 
.Events(e => { e.Open("onOpen");}) 
.Animation(true) 
) 
+0

我不知道究竟發生在這裏。該值將自動發送到服務器。爲什麼你需要通過數據功能發送它? –

回答

0

感謝您的回覆,我有很多自動完成控制我的觀點,我想只寫一個read.Action(「GetCountries」,「收益」)。數據(「onAdditionalData」)函數爲所有這些,我必須得到每個選定的AutoComplete控件的ID在此函數中(獲取用戶輸入的值並將其傳遞給指定的動作),代碼如下:

@(Html.Kendo().AutoComplete() 
.Name("Employee" + (string)Session["fileid"]) 
.Placeholder("Employee Name ...") 
.Filter(FilterType.StartsWith) 
.DataSource(source => 
    { 
    source.Read(read => 
       { 
     read.Action(
        "GetEmployeeName", 
        "Proceeds") 
        .Data("onAdditionalData"); 
     }) 
     .ServerFiltering(true); 
    }) 
    .Animation(true) 
) 

function onAdditionalData() { 
var id = this.element.attr('id');//This line is my problem, because it does not 
//work and I can not get the ID of the currently focused AutoComplete control. 
id = '#' + id; 
return { text: $(id).val() }; 
} 

這是動作部分:

[System.Web.Mvc.HttpGet] 
    public System.Web.Mvc.JsonResult GetEmployeeName(string text) 
    { 
    return Json(/*SOMEVALUES*/, System.Web.Mvc.JsonRequestBehavior.AllowGet); 
    } 

,如果我不使用。數據(「onAdditionalData」)作爲參數發送空行動

0

這裏是爲我工作的方法...

function onAdditionalData(e) { 
    return { text: e.filter.filters[0].value }; 
} 

此外,您可以更改控制器操作名稱來添加字段的ID ...

read.Action("MyAction#" + id, "MyController").Data("onAdditionalData"); 

和訪問attribs這種方式,允許你設置數據參數,並在活動中使用它們:

function onAdditionalData(e) { 
    var filterValue = e.filter.filters[0].value; 
    var field = $(this.url.substring(this.url.indexOf('#'))); 
    return { 
     text: filterValue, 
     extradata1: field.data("extradata1"), 
     extradata2: field.data("extradata2") 
    }; 
} 

URL中的散列標籤將通過瀏覽器獲取到服務器的過程中被刪除。

我使用這種方法來傳遞列表源枚舉和各種其他參數來創建一個非常靈活的AJAX接口。

0

如果你只需要控制的價值,並不在乎你能做到這一點的控制本身...

function onAdditionalData(e) { 
    return { text: e.filter.filters[0].value }; 
    }