Hi
My grid table need to include dropdownlist in one of the cell, and i need to allow user to Add new item to the dropdownlist.
But i not sure how to select and display the New Item after i added the value to database.
Please help.
function
addNewServiceProviderRole(widgetId, value) {
if
(confirm(
"Are you sure?"
)) {
var
formData =
new
FormData();
formData.append(
"role"
, value);
$.ajax({
type:
'POST'
,
url:
'/ServiceProviderRole/AddServiceProviderRole'
,
beforeSend:
function
(xhr) {
xhr.setRequestHeader(
"XSRF-TOKEN"
,
$(
'input:hidden[name="__RequestVerificationToken"]'
).val());
},
contentType:
false
,
processData:
false
,
data: formData,
success:
function
(result) {
if
(result.Errors !=
null
&& result.Errors.length > 0) {
}
else
{
}
}
});
}
}
This is my template.
@using Kendo.Mvc.UI
@(Html.Kendo().DropDownListFor(m => m)
.DataValueField("IServiceProviderRoleId")
.DataTextField("URole")
//.BindTo((System.Collections.IEnumerable)ViewData["roles"])
.Filter(FilterType.Contains)
.NoDataTemplateId("noDataTemplate")
.DataSource(dataSource => dataSource
.Ajax()
.Read(r => r.Url("/ServiceProviderRole/GetAllServiceProviderRole").Data("forgeryToken")))
)
<
script
id
=
"noDataTemplate"
type
=
"text/x-kendo-tmpl"
>
<
div
>
No data found. Do you want to add new item - '#: instance.filterInput.val() #' ?
</
div
>
<
br
/>
<
button
class
=
"k-button"
onclick
=
"addNewServiceProviderRole('#: instance.element[0].id #', '#: instance.filterInput.val() #')"
>Add new item</
button
>
</
script
>