Telerik Forums
UI for ASP.NET MVC Forum
2 answers
4.1K+ views

Hi, I am trying to display images in the Grid and nothing I try works. The images are stored on a database and I convert them to a base64 string in the model. If I render the image directly on the page using <img src="data:image/png;base64,@Model.First().Screenshot" /> the image shows up so I don't there is a problem with the model. However, in the grid, my client template renders  #=Screenshot# as null. Accessing other properties of the model using #=Name#, for example, renders the proper string. What am I doing wrong?

Here is my view

 

@model List<ApplicationViewModel>

<img src="data:image/png;base64,@Model.First().Screenshot" />

<div class="container-fluid">
@(Html.Kendo().Grid<ApplicationViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.Name);
columns.Bound(c => c.Description);
columns.Bound(c => c.Url);
columns.ForeignKey(c => c.Category, (System.Collections.IEnumerable)ViewBag.cats, "ID", "Category");
columns.Bound(f => f.Screenshot).ClientTemplate("#:Screenshot# <img src='data: image/png; base64,#=Screenshot#' />");
columns.Command(cmd => cmd.Edit());
})
.ToolBar(toolbar =>
{
toolbar.Create();
})
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("ApplicationTemplate"))
.HtmlAttributes(new { style = "height:90vh; width:100%" })
.Scrollable()
.Sortable()
.Pageable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action("ApplicationRead", "Admin"))
.Model(model =>
{
model.Id(p => p.ID);
model.Field(p => p.ID).Editable(false);
})
.Create(update => update.Action("CreateApplication", "Admin"))
.Update(update => update.Action("UpdateApplication", "Admin"))
.Destroy(update => update.Action("DestroyApplication", "Admin"))
))
</div>
</body>
</html>

Tomasz
Top achievements
Rank 1
 answered on 30 Nov 2017
2 answers
704 views

Hello,

I'm trying to setup a specific display format for a DatePicker when using DateInput. The following works fine functionally:

@(Html.Kendo().DatePicker()
.Format("yyyy-MM-dd")
.DateInput()
.Name("dpSitOpenDate")
.HtmlAttributes(new { style = "width:90%"})
)

 

My issue with this is that when DateInput() is active, it displays: "Year-Month-Day" before any date is entered. I would prefer it to show "yyyy-mm-dd" instead, so that users know exactly what format is expected of them before they start typing.

 

I know that a DateInput control by itself has the possibility to enter custom Messages which I believe would have the effect I want, as explained in the Localization example of this page:

https://docs.telerik.com/kendo-ui/controls/editors/dateinput/overview

 

Is it possible to setup those messages on the DateInput that is embedded in the DatePicker? The only parameter that can seemingly be passed to .DateInput() is a Boolean, so I'm not sure how I could set those messages during creation, and I'm not sure how I would access the DateInput via script either. I know I can access the DatePicker itself via $("#dpSitOpenDate").data("kendoDatePicker") for example, but not the DateInput within it.

 

Thank you!

Luc
Top achievements
Rank 1
 answered on 30 Nov 2017
1 answer
123 views

Hi,

I have a Chart with Line and Column Series, programmatically populated from the Sequel server.

My requirement is to custom color the Column series (those bar which  appear on the graph per month wise) based on the values of the  Line series.

Any column bar whose value is less then the Line series bar to be shown in one color and the values which are more in another color.

Attached is the  graph for reference, Thanks in advance for your support in this regards.

 

Alex Hajigeorgieva
Telerik team
 answered on 30 Nov 2017
1 answer
99 views

In timeline month view, is it possible to navigate a single day, forward and for example see:

-  event from 2017-12-02  -   2018.01.02

 

Neli
Telerik team
 answered on 30 Nov 2017
5 answers
1.4K+ views

I have a Kendo Grid (MVC) that has multiple Columns.

I have a use case where if Column 1 is edited, the value of Column 2 may change server-side. I'm not seeing the modified values in the grid though.

My Update API handles all of this and returns the updated row. But with inline editing, it seems that if I update Column 1, the other columns aren't refreshing after the Update is finished. So I (the user) has to manually refresh the Grid in order to see Column 2 correctly modified.

What am I doing wrong?

StackOverflow thread with same question: https://stackoverflow.com/q/47354235/590774

 

Feel free to answer anywhere.

Stefan
Telerik team
 answered on 30 Nov 2017
2 answers
390 views

I have a kendo grid with inline editing enabled. One of the field is a datetime field and it is configured to be non-editable. After a update(or delete) action is triggered, the millisecond part of the value of the field is lost in the controller. Is there anyway to avoid it?

Zhang
Top achievements
Rank 1
 answered on 30 Nov 2017
3 answers
693 views

HI

I found there have a problem about Grid.Pageable() and DataSource.PageSize().

If you set Grid.Pageable(false) and Grid becomes unpageable(this is OK)
but DataSource.PageSize(m) setting still applied (Grid still show m records at once, not all records).

I think when Grid.Pageable(false) and Grid should show all records absolutely, RIGHT ? 

  @(Html.Kendo().Grid(Model.MyList1)
    .Name("MyList1Grid")
    .Pageable(pageable => pageable.Enabled(false))
    ...
    .DataSource(dataSource => 
    {
      dataSource.Ajax()
        .PageSize(3)
        .ServerOperation(false)
        .Model(model => model.Id(m => m.UniqueID))
    })
    ...;

*Telerik DevCraft UI for ASP.NET MVC R2 2017 SP1

Best regards

Chris

 

 

Stefan
Telerik team
 answered on 29 Nov 2017
1 answer
119 views

Hello,

We used Kendo UI Editor in our MVC project and realized that scroll bar display all the time even message is very short. Our client asked us to display scroll bar only when it is necessary. Does anyone has solution for it?   Thanks in advance.

Neli
Telerik team
 answered on 29 Nov 2017
5 answers
335 views

Hi,

I am new to Telerik. I am doing a trial with Telerik Grid using ASP.Net MVC. I couldn't get my grid to display data when the page is loaded. Below are my code blocks:

1. ProductService:

using System;<br>using System.Collections.Generic;<br>using System.Data;<br>using System.Linq;<br>using System.Web;<br>using System.Data.Entity;<br><br>namespace AdmManagerBeta.Models<br>{<br>    public class ProductService : IDisposable<br>    {<br>        private static bool UpdateDatabase = false;<br>        private ADMUsersEntities entities;<br><br>        public ProductService(ADMUsersEntities entities)<br>        {<br>            this.entities = entities;<br>        }<br><br>        public IList<ProductViewModel> GetAll()<br>        {<br>            var result = HttpContext.Current.Session["Products"] as IList<ProductViewModel>;<br><br>            if (result == null || UpdateDatabase)<br>            {<br>                result = entities.Products.Select(product => new ProductViewModel<br>                {<br>                    ProductID = product.ProductID,<br>                    ProductName = product.ProductName<br>                    //UnitPrice = product.UnitPrice.HasValue ? product.UnitPrice.Value : default(decimal),<br>                    //UnitsInStock = product.UnitsInStock.HasValue ? product.UnitsInStock.Value : default(short),<br>                    //QuantityPerUnit = product.QuantityPerUnit,<br>                    //Discontinued = product.Discontinued,<br>                    //UnitsOnOrder = product.UnitsOnOrder.HasValue ? (int)product.UnitsOnOrder.Value : default(int),<br>                    //CategoryID = product.CategoryID,<br>                    //Category = new CategoryViewModel()<br>                    //{<br>                    //    CategoryID = product.Category.CategoryID,<br>                    //    CategoryName = product.Category.CategoryName<br>                    //},<br>                    //LastSupply = DateTime.Today<br>                }).ToList();<br><br>                HttpContext.Current.Session["Products"] = result;<br>            }<br><br>            return result;<br>        }<br><br>        public IEnumerable<ProductViewModel> Read()<br>        {<br>            return GetAll();<br>        }<br><br>        public void Create(ProductViewModel product)<br>        {<br>            if (!UpdateDatabase)<br>            {<br>                var first = GetAll().OrderByDescending(e => e.ProductID).FirstOrDefault();<br>                var id = (first != null) ? first.ProductID : 0;<br><br>                product.ProductID = id + 1;<br><br>                if (product.CategoryID == null)<br>                {<br>                    product.CategoryID = 1;<br>                }<br><br>                if (product.Category == null)<br>                {<br>                    product.Category = new CategoryViewModel() { CategoryID = 1, CategoryName = "Beverages" };<br>                }<br><br>                GetAll().Insert(0, product);<br>            }<br>            else<br>            {<br>                var entity = new Product();<br><br>                entity.ProductName = product.ProductName;<br>                entity.UnitPrice = product.UnitPrice;<br>                entity.UnitsInStock = (short)product.UnitsInStock;<br>                entity.Discontinued = product.Discontinued;<br>                entity.CategoryID = product.CategoryID;<br><br>                if (entity.CategoryID == null)<br>                {<br>                    entity.CategoryID = 1;<br>                }<br><br>                if (product.Category != null)<br>                {<br>                    entity.CategoryID = product.Category.CategoryID;<br>                }<br><br>                entities.Products.Add(entity);<br>                entities.SaveChanges();<br><br>                product.ProductID = entity.ProductID;<br>            }<br>        }<br><br>        public void Update(ProductViewModel product)<br>        {<br>            if (!UpdateDatabase)<br>            {<br>                var target = One(e => e.ProductID == product.ProductID);<br><br>                if (target != null)<br>                {<br>                    target.ProductName = product.ProductName;<br>                    target.UnitPrice = product.UnitPrice;<br>                    target.UnitsInStock = product.UnitsInStock;<br>                    target.Discontinued = product.Discontinued;<br><br>                    if (product.CategoryID == null)<br>                    {<br>                        product.CategoryID = 1;<br>                    }<br><br>                    if (product.Category != null)<br>                    {<br>                        product.CategoryID = product.Category.CategoryID;<br>                    }<br>                    else<br>                    {<br>                        product.Category = new CategoryViewModel()<br>                        {<br>                            CategoryID = (int)product.CategoryID,<br>                            CategoryName = entities.Categories.Where(s => s.CategoryID == product.CategoryID).Select(s => s.CategoryName).First()<br>                        };<br>                    }<br><br>                    target.CategoryID = product.CategoryID;<br>                    target.Category = product.Category;<br>                }<br>            }<br>            else<br>            {<br>                var entity = new Product();<br><br>                entity.ProductID = product.ProductID;<br>                entity.ProductName = product.ProductName;<br>                entity.UnitPrice = product.UnitPrice;<br>                entity.UnitsInStock = (short)product.UnitsInStock;<br>                entity.Discontinued = product.Discontinued;<br>                entity.CategoryID = product.CategoryID;<br><br>                if (product.Category != null)<br>                {<br>                    entity.CategoryID = product.Category.CategoryID;<br>                }<br><br>                entities.Products.Attach(entity);<br>                entities.Entry(entity).State = EntityState.Modified;<br>                entities.SaveChanges();<br>            }<br>        }<br><br>        public void Destroy(ProductViewModel product)<br>        {<br>            if (!UpdateDatabase)<br>            {<br>                var target = GetAll().FirstOrDefault(p => p.ProductID == product.ProductID);<br>                if (target != null)<br>                {<br>                    GetAll().Remove(target);<br>                }<br>            }<br>            else<br>            {<br>                var entity = new Product();<br><br>                entity.ProductID = product.ProductID;<br><br>                entities.Products.Attach(entity);<br><br>                entities.Products.Remove(entity);<br><br>                var orderDetails = entities.Order_Details.Where(pd => pd.ProductID == entity.ProductID);<br><br>                foreach (var orderDetail in orderDetails)<br>                {<br>                    entities.Order_Details.Remove(orderDetail);<br>                }<br><br>                entities.SaveChanges();<br>            }<br>        }<br><br>        public ProductViewModel One(Func<ProductViewModel, bool> predicate)<br>        {<br>            return GetAll().FirstOrDefault(predicate);<br>        }<br><br>        public void Dispose()<br>        {<br>            entities.Dispose();<br>        }<br>    }<br>}

 

2. ProductController.cs:

using AdmManagerBeta.Models;<br>using Kendo.Mvc.Extensions;<br>using Kendo.Mvc.UI;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Web.Mvc;<br><br>namespace AdmManagerBeta.Controllers<br>{<br>    public class ProductController : Controller<br>    {<br>        private ProductService productService;<br><br>        public ProductController()<br>        {<br>            productService = new ProductService(new ADMUsersEntities());<br>        }<br><br>        protected override void Dispose(bool disposing)<br>        {<br>            productService.Dispose();<br><br>            base.Dispose(disposing);<br>        }<br>        public ActionResult Index()<br>        {<br>            return View();<br>        }<br><br>        public ActionResult Editing_Read([DataSourceRequest] DataSourceRequest request)<br>        {<br>            return Json(productService.Read().ToDataSourceResult(request));<br>        }<br><br>        [AcceptVerbs(HttpVerbs.Post)]<br>        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductViewModel> products)<br>        {<br>            var results = new List<ProductViewModel>();<br><br>            if (products != null && ModelState.IsValid)<br>            {<br>                foreach (var product in products)<br>                {<br>                    productService.Create(product);<br>                    results.Add(product);<br>                }<br>            }<br><br>            return Json(results.ToDataSourceResult(request, ModelState));<br>        }<br><br>        [AcceptVerbs(HttpVerbs.Post)]<br>        public ActionResult Editing_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductViewModel> products)<br>        {<br>            if (products != null && ModelState.IsValid)<br>            {<br>                foreach (var product in products)<br>                {<br>                    productService.Update(product);<br>                }<br>            }<br><br>            return Json(products.ToDataSourceResult(request, ModelState));<br>        }<br><br>        [AcceptVerbs(HttpVerbs.Post)]<br>        public ActionResult Editing_Destroy([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductViewModel> products)<br>        {<br>            if (products.Any())<br>            {<br>                foreach (var product in products)<br>                {<br>                    productService.Destroy(product);<br>                }<br>            }<br><br>            return Json(products.ToDataSourceResult(request, ModelState));<br>        }<br>    }<br>}<br>

 

3. Index.cshtml:

@using Kendo.Mvc.UI;<br><br>@(Html.Kendo().Grid<AdmManagerBeta.Models.ProductViewModel>()<br>    .Name("Grid")<br>    .Columns(columns =><br>    {<br>        columns.Bound(p => p.ProductName);<br>        columns.Bound(p => p.UnitPrice).Width(140);<br>        columns.Bound(p => p.UnitsInStock).Width(140);<br>        columns.Bound(p => p.Discontinued).Width(100);<br>        columns.Command(command => command.Destroy()).Width(150);<br>    })<br>    .ToolBar(toolbar =><br>    {<br>        toolbar.Create();<br>        toolbar.Save();<br>    })<br>    .Editable(editable => editable.Mode(GridEditMode.InCell))<br>    .Pageable()<br>    .Navigatable()<br>    .Sortable()<br>    .Scrollable()<br>    .DataSource(dataSource => dataSource<br>        .Ajax()<br>        .Batch(true)<br>        .PageSize(20)<br>        .ServerOperation(false)<br>        .Events(events => events.Error("error_handler"))<br>        .Model(model => model.Id(p => p.ProductID))<br>        .Create("Editing_Create", "Product")<br>        .Read("Editing_Read", "Product")<br>        .Update("Editing_Update", "Product")<br>        .Destroy("Editing_Destroy", "Product")<br>    )<br>)<br><script type="text/javascript"><br>    function error_handler(e) {<br>        if (e.errors) {<br>            var message = "Errors:\n";<br>            $.each(e.errors, function (key, value) {<br>                if ('errors' in value) {<br>                    $.each(value.errors, function() {<br>                        message += this + "\n";<br>                    });<br>                }<br>            });<br>            alert(message);<br>        }<br>    }<br></script>

 

4. _Layout.cshtml:

<p><!DOCTYPE html><br><html><br><head><br>    <title>@ViewBag.Title - My Telerik MVC Application</title><br>    <link href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.common.min.css" rel="stylesheet"><br>    <link href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.metro.min.css" rel="stylesheet"><br>    <link href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.dataviz.min.css" rel="stylesheet"><br>    <link href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.dataviz.metro.min.css" rel="stylesheet"><br>       <link href="https://kendo.cdn.telerik.com/2017.3.1026/styles/kendo.common.min.css" rel="stylesheet" type="text/css" /><br>    <script src="https://kendo.cdn.telerik.com/2017.3.1026/js/jquery.min.js"></script><br>  <script src="https://kendo.cdn.telerik.com/2017.3.1026/js/jszip.min.js"></script><br>   <script src="https://kendo.cdn.telerik.com/2017.3.1026/js/kendo.all.min.js"></script><br>   <script src="https://kendo.cdn.telerik.com/2017.3.1026/js/kendo.aspnetmvc.min.js"></script><br><script src="http://code.jquery.com/jquery-1.8.2.min.js"></script><br>    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /><br>      <script src="@Url.Content("~/Scripts/kendo.modernizr.custom.js")"></script><br></head><br><body><br>    <header><br>        <div class="content-wrapper"><br>            <div class="float-left"><br>                <p class="site-title">@Html.ActionLink("your logo here", "Index", "Home")</p><br>            </div><br>            <div class="float-right"><br>                <nav><br>                    <ul id="menu"><br>                        <li>@Html.ActionLink("Home", "Index", "Home")</li><br>                        <li>@Html.ActionLink("Register", "Index", "Register")</li><br>                        <li>@Html.ActionLink("Login", "Index", "Login")</li><br>                        <li>@Html.ActionLink("Product", "Index", "Product")</li><br>                    </ul><br>                </nav><br>            </div><br>        </div><br>    </header><br>    <div id="body"><br>        @RenderSection("featured", required: false)<br>        <section class="content-wrapper main-content clear-fix"><br>            @RenderBody()<br>        </section><br>    </div><br>    <footer><br>        <div class="content-wrapper"><br>            <div class="float-left"><br>                <p>&copy; @DateTime.Now.Year - My Telerik MVC Application</p><br>            </div><br>        </div><br>    </footer><br></body><br></html></p><p></p><p></p><p></p>

 

 

Stefan
Telerik team
 answered on 29 Nov 2017
3 answers
252 views

Hi,

I am trying to use editor template in grid and for that i have html partial view but i am unable to find the way to send the bounded context to my partial view. can you please help guys ??

 

 

Viktor Tachev
Telerik team
 answered on 29 Nov 2017
Narrow your results
Selected tags
Tags
Grid
General Discussions
Scheduler
DropDownList
Chart
Editor
TreeView
DatePicker
Upload
ComboBox
MultiSelect
ListView
Window
TabStrip
Menu
Installer and VS Extensions
Spreadsheet
AutoComplete
TreeList
Gantt
PanelBar
NumericTextBox
Filter
ToolTip
Map
Diagram
Button
PivotGrid
Form
ListBox
Splitter
Application
FileManager
Sortable
Calendar
View
MaskedTextBox
PDFViewer
TextBox
Toolbar
MultiColumnComboBox
Dialog
DropDownTree
Checkbox
Slider
Switch
Notification
ListView (Mobile)
Pager
Accessibility
ColorPicker
DateRangePicker
Wizard
Security
Styling
Chat
MediaPlayer
TileLayout
DateInput
Drawer
SplitView
Barcode
ButtonGroup (Mobile)
Drawer (Mobile)
ImageEditor
RadioGroup
Sparkline
Stepper
TabStrip (Mobile)
GridLayout
Template
Badge
LinearGauge
ModalView
ResponsivePanel
TextArea
Breadcrumb
ExpansionPanel
Licensing
Rating
ScrollView
ButtonGroup
CheckBoxGroup
NavBar
ProgressBar
QRCode
RadioButton
Scroller
Timeline
TreeMap
TaskBoard
OrgChart
Captcha
ActionSheet
Signature
DateTimePicker
AppBar
BottomNavigation
Card
FloatingActionButton
Localization
MultiViewCalendar
PopOver (Mobile)
Ripple
ScrollView (Mobile)
Switch (Mobile)
PivotGridV2
FlatColorPicker
ColorPalette
DropDownButton
AIPrompt
PropertyGrid
ActionSheet (Mobile)
BulletGraph
Button (Mobile)
Collapsible
Loader
CircularGauge
SkeletonContainer
Popover
HeatMap
Avatar
ColorGradient
CircularProgressBar
SplitButton
StackLayout
TimeDurationPicker
Chip
ChipList
DockManager
ToggleButton
Sankey
OTPInput
ChartWizard
SpeechToTextButton
InlineAIPrompt
TimePicker
StockChart
RadialGauge
ContextMenu
ArcGauge
AICodingAssistant
+? more
Top users last month
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?