I developed a Grid which displays a pop-up for updates. Popup Edit screen is a Custom template with a dropdown list that calls the controller to populate the dropdown. In this case, i am populating the prefixes. The is populated fine, but when I click on a row on the grid to edit an item, I need to pre-select the value in the drop-down. let's say if a particular row has a value of "Mr." as a prefix, I need it to be pre-selected in the popup .
If the use of a @Html.EditorFor(model => model.Prefix), it perfectly populates the editor fine. This doesn't work for Dropdown.
The editor template is called MemberEdit and the code in it is as below:
<
p
></
p
><
p
>@model <
g
class
=
"gr_ gr_98 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace"
id
=
"98"
data-gr-id
=
"98"
>Api</
g
>.<
g
class
=
"gr_ gr_162 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation multiReplace"
id
=
"162"
data-gr-id
=
"162"
>Common..</
g
>Models.WebUser<
br
><
br
> <
div
class
=
"row"
style
=
"margin-left:5px;"
><
br
> <
div
class
=
"col-lg-2"
><
br
> @Html.LabelFor(model => model.Prefix)<
br
> @*@Html.EditorFor(model => model.Prefix)*@<
br
> @(Html.Kendo().DropDownList()<
br
> .Name("ddlPrefix")<
br
> .DataTextField("Prefix")<
br
> .DataValueField("PrefixKey")<
br
> .DataSource(source =><
br
> {<
br
> source.Read(read =><
br
> {<
br
> read.Action("ListCustomerPrefix", "Home"); //.Data("additionalPrefixData");<
br
> })<
br
> .ServerFiltering(true);<
br
> })<
br
> // .Text(Model.Prefix)<
br
> .Value(Model.PrefixKey)<
br
> .AutoBind(false)<
br
> .HtmlAttributes(new { style = "width: 100%" })<
br
> )<
br
> @Html.ValidationMessageFor(model => model.Prefix)<
br
> </
div
><
br
> </
div
></
p
>
The Grid code is as shown below:
1.
@(Html.Kendo().Grid<.Api.Common..Models.WebUser>()<
br
> .Name("membersGrid")<
br
> .Columns(columns =><
br
> {<
br
> columns.Command(command => { command.Edit(); command.Destroy().Text("Del"); }).Width("15%");<
br
> columns.Bound(p => p.CST_KEY).Visible(false);<
br
> columns.Bound(p => p.FullName).Width("20%").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains").SuggestionOperator(FilterType.Contains)));<
br
> columns.Bound(p => p.Role).Width("25%").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains").SuggestionOperator(FilterType.Contains)));<
br
> columns.Bound(p => p.Title).Width("20%").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains").SuggestionOperator(FilterType.Contains)));<
br
> columns.Bound(p => p.EmailAddress).Width("20%").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains").SuggestionOperator(FilterType.Contains)));<
br
> columns.Bound(p => p.Prefix).Visible(false);<
br
> columns.Bound(p => p.Suffix).Visible(false);<
br
> columns.Bound(p => p.RoleKey).Visible(false);<
br
> columns.Bound(p => p.OrganizationMemberKey).Visible(false);<
br
><
br
> }).Filterable(filterable => filterable<
br
> .Extra(false)<
br
> .Operators(ops => ops<
br
> .ForString(str => str.Clear()<
br
> .Contains("Contains")<
br
> .StartsWith("Starts With")<
br
> .IsEqualTo("Is Equal To")<
br
> .IsNotEqualTo("Is Not Equal To")<
br
> )))<
br
> .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("MemberEdit").Window(w => w.Title("Edit Employee").Width(1100)))<
br
> .Pageable(pager => pager.AlwaysVisible(false).PageSizes(new List<
object
> { 5, 10, 15, 20 }))<
br
> .Sortable()<
br
> .Filterable(ftb => ftb.Mode(GridFilterMode.Row))<
br
> .HtmlAttributes(new { style = "width:100%;" })<
br
> .DataSource(dataSource => dataSource<
br
> .Ajax()<
br
> .PageSize(10)<
br
> .Events(events => events.Error("error_handler"))<
br
> .Model(model => model.Id(p => p.CST_KEY))<
br
> .Read(read => read.Action("ListMembers", "Home"))<
br
> .Update(update => update.Action("EditingPopup_Update", "Home"))<
br
> .Model(model =><
br
> {<
br
> model.Field(m => m.Title);<
br
> model.Field(m => m.Prefix);<
br
> model.Field(m => m.PrefixKey);<
br
> model.Field(m => m.Suffix);<
br
> model.Field(m => m.FirstName);<
br
> model.Field(m => m.MiddleName);<
br
> model.Field(m => m.LastName);<
br
> model.Field(m => m.OrganizationKey);<
br
> model.Field(m => m.FullName);<
br
> model.Field(m => m.CustomerId);<
br
> model.Field(m => m.OrganizationMemberKey);<
br
> model.Field(m => m.EmailAddress);<
br
> model.Field(m => m.CST_KEY);<
br
> model.Field(m => m.Role);<
br
> model.Field(m => m.RoleKey);<
br
> model.Field(m => m.RoleList).DefaultValue(new List<
Aamva.Api.Common.WebSite.Models.WebUserRole
>());<
br
> }<
br
> )<
br
> )<
br
> )
The Model is as below:
public
class
WebUser<br> {<br>
public
string
CST_KEY {
get
;
set
; }<br>
public
string
EmailAddress {
get
;
set
; }<br>
public
string
Prefix {
get
;
set
; }<br>
public
string
PrefixKey {
get
;
set
; }<br>
public
string
Suffix {
get
;
set
; }<br>
public
string
Title {
get
;
set
; }<br>
public
string
FirstName {
get
;
set
; }<br>
public
string
MiddleName {
get
;
set
; }<br>
public
string
LastName {
get
;
set
; }<br>
public
string
OrganizationKey {
get
;
set
; }<br>
public
string
OrganizationMemberKey {
get
;
set
; }<br>
public
string
OrganizationName {
get
;
set
; }<br>
public
string
Role {
get
;
set
; }<br>
public
string
RoleKey {
get
;
set
; }<br>
public
List<WebUserRole> RoleList {
get
;
set
; }<br>
}
The Model for Prefix is as below:
public
class
WebUserPrefix<br> {<br>
public
string
PrefixKey {
get
;
set
; }<br>
public
string
Prefix {
get
;
set
; }<br> }
We are working on a Kendo UI with
Kendo Listbox (asp.net MVC - https://demos.telerik.com/aspnet-mvc/listbox)
but the example is for
@html.Kendo().ListBox() rather than having @html.Kendo.ListBoxFor() where @html.Kendo.ListBoxFor() allows for the model to be BindTo to selected items
Is there a way a ListBox can be used to bind to a model rather than an IEnumerable so that we can pass data back and forth via the model
Hi,
I'm having some problems when I try to format text when there is a span in the middle of the selected text. Below I've shown the before, after and expected HTML when I try to change the change the font size, for example, by highlighting a word on either side of my span as well as the span itself.
BEFORE:
<
p
>one two <
span
k-immutable
=
"6qxG2g5C1I"
></
span
> three four</
p
>
AFTER:
<
p
>one <
span
style
=
"font-size:72pt;"
>two </
span
><
span
k-immutable
=
"6qxG2g5C1I"
></
span
><
span
style
=
"font-size:72pt;"
> three</
span
> four</
p
>
EXPECTED:
<
p
>one <
span
style
=
"font-size:72pt;"
>two <
span
k-immutable
=
"6qxG2g5C1I"
></
span
> three</
span
> four</
p
>
We use the <span k-immutable="6qxG2g5C1I"> as a merge field so my question is this: is there any way to catch when font is changed through the toolbar (font-size, font-alignment, font-change, font-bold,etc) or is there a way to better wrap around the middle span so that it doesn't ignore the changes I've made?
I have model as
public class ProductViewModel
{
public int ID { get; set; }
public string ProductName { get; set; }
public double? Price { get; set; }
}
The controller is
public ActionResult Products([DataSourceRequest]DataSourceRequest request)
{
List<Models.ProductViewModel> lst = new List<Models.ProductViewModel>();
lst = GetGridData().ToList();
DataSourceResult result = lst.ToDataSourceResult(request, p => new Models.Product
{
ID = p.ID,
ProductName = p.ProductName,
Price = p.Price
});
return Json(result, JsonRequestBehavior.AllowGet);
}
public IEnumerable<Models.ProductViewModel> GetGridData()
{
List<Models.ProductViewModel> objProducts = new List<Models.ProductViewModel>();
for (int i = 1; i<= 10; i++)
{
objProducts.Add(new Models.ProductViewModel() { ID = i, ProductName = "Prod" + i.ToString(), Price = i * 10 });
}
return objProducts.ToList().AsEnumerable();
}
cshtml
@model TelerikMvcApp1.Models.ProductViewModel
@using System.Web.Optimization
@using Kendo.Mvc.UI
@using Kendo.Mvc.Extensions
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div>
@(Html.Kendo().Grid<TelerikMvcApp1.Models.ProductViewModel>()
.Name("grid")
.DataSource(dataSource => dataSource //Configure the Grid data source.
.Ajax() //Specify that Ajax binding is used.
.ServerOperation(false) //Paging, sorting, filtering, and grouping will be done client-side.
.Read(read => read
.Action("About", "Home")) //Set the action method which will return the data in JSON format.
//.Data("productsReadData") //Specify the JavaScript function which will return the data.
)
.Columns(columns =>
{
//Create a column bound to the ProductID property.
columns.Bound(P => P.ID).Title("Product ID");
//Create a column bound to the ProductName property.
columns.Bound(P => P.ProductName).Title("Product Name").Width(130);
//Create a column bound to the UnitsInStock property.
columns.Bound(P => P.Price);
})
.Pageable() // Enable paging
.Sortable() // Enable sorting
.HtmlAttributes(new { style = "height: 550px; width:300px;" })
)
</div>
When I run the application, Grid is not displayed and the output is
{"Data":[{"ID":1,"ProductName":"Prod1","Price":10},{"ID":2,"ProductName":"Prod2","Price":20},{"ID":3,"ProductName":"Prod3","Price":30},{"ID":4,"ProductName":"Prod4","Price":40},{"ID":5,"ProductName":"Prod5","Price":50},{"ID":6,"ProductName":"Prod6","Price":60},{"ID":7,"ProductName":"Prod7","Price":70},{"ID":8,"ProductName":"Prod8","Price":80},{"ID":9,"ProductName":"Prod9","Price":90},{"ID":10,"ProductName":"Prod10","Price":100}],"Total":10,"AggregateResults":null,"Errors":null}
Hi I am struggling to figure this out...I am trying to pass additional data on the call. The id that treeview comes up with is always there and correct. But my roleid is always null. And the RoleId is valid number. Running out of places to look so I figured I post...
@(Html.Kendo().TreeView()
.Name("permissionList")
.Checkboxes(true)
.DataTextField("name")
.DataSource(dataSource => dataSource
.Read(read => read.Action("permissions", "roles", new { RoleId = @Model.RoleId}))
)
)
Controller
[HttpGet]
[Route("permissions")]
[Route("permissions/{id}/{RoleId}")]
public JsonResult Permissions(int? id, int? RoleId)
{
var roleFormMgr = new RoleFormMgr(StateMgmt);
var roleEntity = roleFormMgr.GetRole(RoleId.GetValueOrDefault());
var roleFormVM = roleFormMgr.PopulateView(Mapper.Map<RoleForm>(roleEntity));
var permissions = roleFormVM.RolePermissionList.Where(p => id.HasValue ? p.parentId == id : (id == null && p.parentId == 0)).ToList();
return Json(permissions, JsonRequestBehavior.AllowGet);
}
How can I limit the editable text to a positive number .
My Grid is as follows:
@(Html.Kendo().Grid<TelerikMvcApp1.Models.ProductViewModel>()
.Name("Grid")
.DataSource(dataSource => dataSource //Configure the Grid data source.
.Ajax() //Specify that Ajax binding is used.
.Batch(true)
.ServerOperation(false) //Paging, sorting, filtering, and grouping will be done client-side.
.Read(read => read
.Action("Products", "Home")) //Set the action method which will return the data in JSON format.
//.Data("productsReadData") //Specify the JavaScript function which will return the data.
.Model(model => model.Id(p => p.Id))
)
.Columns(columns =>
{
columns.Bound(P => P.Id).Title("ID").Width(20).Editable("NoEditing").HtmlAttributes(new { style = "text-align:center" }).HeaderHtmlAttributes(new { style = "text-align:center" });
columns.Bound(P => P.ProductName).Title("Product Name").Width(40).Editable("NoEditing").HtmlAttributes(new { style = "text-align:center" }).HeaderHtmlAttributes(new { style = "text-align:center" });
columns.Bound(P => P.Price).Editable("AllowEditing").HtmlAttributes(new { style = "text-align:center" }).HeaderHtmlAttributes(new { style = "text-align:center" }).Width(30); //.ClientTemplate("<input type=\"number\" value=#= Inches # min=\"0\" max=\"11\" step=\"1\" ></input>");
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
//.Pageable() // Enable paging
.Sortable() // Enable sorting
.Scrollable()
.Filterable()
.Navigatable()
.HtmlAttributes(new { style = "height: 300px;" })
)
<script>
function AllowEditing(dataItem) {
return true;
}
function NoEditing(dataItem) {
return false;
}
I tried adding a ClientTemplate which is commented above. But that didn't work.
In the demos I was able to see something like
.Format("MMMM yyyy")
But I have been unable to find the valid values for the string input or documentation on the Format method itself. I am obviously looking in the wrong place. Where should I look?
Thank you.
We're dealing with a strange error that appears to be a race condition while the kendo menu is checking permissions to "trim" the menu items. The error message we've logged is: System.IndexOutOfRangeExceptionIndex was outside the bounds of the array (see stack trace below).
This seems to be a race condition as it happens infrequently, and apparently only at times of heavy use. We also can't reproduce it in any of our test or development environments; we see it logged only in production.
I've downloaded the kendo source bundle, but it (rather surprisingly) doesn't contain any C# code! So we can't actually get any insight into what might be causing this error to be thrown by the MVC menu wrapper.
My guess is that the kendo menu is parallelizing the requests to check action authorization, and in rare cases this causes a race condition on the collection access (again, see stack trace) which is not thread-safe.
Can you provide any guidance on this issue?
Thanks!
Stack Trace:
System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.ArrayList.Add(Object value)
at Kendo.Mvc.Infrastructure.Implementation.ControllerAuthorization.IsAccessibleToUser(RequestContext requestContext, String controllerName, String actionName, RouteValueDictionary routeValues)
at Kendo.Mvc.Infrastructure.Implementation.NavigationItemAuthorization.IsAccessibleToUser(RequestContext requestContext, INavigatable navigationItem)
at Kendo.Mvc.UI.NavigationItemContainerExtensions.WriteItem[TComponent,TItem](TItem item, TComponent component, IHtmlNode parentTag, INavigationComponentHtmlBuilder`1 builder)
at Kendo.Mvc.UI.NavigationItemContainerExtensions.<>c__DisplayClass5`2.<WriteItem>b__1(TItem child)
at Kendo.Mvc.Extensions.EnumerableExtensions.Each[T](IEnumerable`1 instance, Action`1 action)
at Kendo.Mvc.UI.NavigationItemContainerExtensions.WriteItem[TComponent,TItem](TItem item, TComponent component, IHtmlNode parentTag, INavigationComponentHtmlBuilder`1 builder)
at Kendo.Mvc.UI.Menu.<>c__DisplayClass1.<WriteHtml>b__0(MenuItem item)
at Kendo.Mvc.Extensions.EnumerableExtensions.Each[T](IEnumerable`1 instance, Action`1 action)
at Kendo.Mvc.UI.Menu.WriteHtml(HtmlTextWriter writer)
at Kendo.Mvc.UI.WidgetBase.ToHtmlString()
at Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.ToHtmlString()
at System.Web.WebPages.WebPageBase.Write(Object value)
at ASP._Page_Views_Menu_Application_cshtml.Execute() in d:\WWWRoot\SASB\Views\Menu\Application.cshtml:line 14
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.<>c__DisplayClass4.<Wrap>b__3()
at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func`1 func)
at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage)
at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)
at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter)
at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues)
at ASP._Page_Views_Shared__ApplicationLayout_cshtml.Execute() in d:\WWWRoot\SASB\Views\Shared\_ApplicationLayout.cshtml:line 9
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.WebPages.WebPageBase.<>c__DisplayClass3.<RenderPageCore>b__2(TextWriter writer)
at System.Web.WebPages.WebPageBase.Write(HelperResult result)
at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)
at System.Web.WebPages.WebPageBase.PopContext()
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
@(Html.Kendo().Upload()
.Name(
"Attachments"
).Multiple(
true
).ShowFileList(
true
)
.Async(async => async
.Save(
"Attach"
,
"Controller"
,
new
{ entryId = Model.Id })
.Remove(
"RemoveAttachment"
,
"Controller"
,
new
{ entryId = Model.Id }))
.Files(files => {
if
(Model.Attachments !=
null
)
{
foreach
(var f
in
Model.Attachments)
{
files.Add().Name(f);
}
}
}))