Reputation: 307
I am using Kendo UI ListView with SignalR to my ASP.Net MVC application as below code sample:
CSHTML code:
@(Html.Kendo().ListView<TestApp.Models.testViewModel>()
.Name("LVTest")
.TagName("div")
.ClientTemplateId("templateTest")
.DataSource(dataSource => dataSource
.SignalR()
.Transport(tr => tr
.Promise("hubStart")
.Hub("testHub")
.Client(c => c.Read("test_Read"))
.Server(s => s.Read("test_Read"))
)
.Schema(schema => schema
.Model(m => { m.Id(p => p.Id); })
)
)
)
HUB code:
public IEnumerable<TestViewModel> Test_Read(string CurrencyId)
{
var queryResult = TestRepository.Test_Read(CurrencyId);
return queryResult;
}
I would like to pass the CurrencyId as a parameter to the read method here. I can achieve this by using the .Data method of datasource for Ajax binding but need to achieve this by suing SignalR. How can I pass the parameter to the read method herre?
Upvotes: 1
Views: 1357
Reputation: 307
Found the solution using ParameterMap as below:
CSHTML code
<script>
function customParameterMap(data, operation) {
var selectedEmpId = $("#ddlEmp").data("kendoDropDownList").value();
if (operation === "read") {
data.selectedEmpId = selectedEmpId;
}
return data;
}
@(Html.Kendo().ListView<TestApp.Models.testViewModel>()
.Name("LVTest")
.TagName("div")
.ClientTemplateId("templateTest")
.DataSource(dataSource => dataSource
.SignalR()
.Transport(tr => tr
.ParameterMap("customParameterMap")
.Promise("hubStart")
.Hub("testHub")
.Client(c => c.Read("test_Read"))
.Server(s => s.Read("test_Read"))
)
.Schema(schema => schema
.Model(m => { m.Id(p => p.Id); })
)
)
)
HUB code
public class ReadRequestData
{
public string selectedEmpId { get; set; }
}
public IEnumerable<TestViewModel> Test_Read(ReadRequestData data)
{
string EmpId = data.selectedEmpId;
var queryResult = TestRepository.Test_Read(EmpId);
return queryResult;
}
Upvotes: 1