Telerik Forums
UI for ASP.NET MVC Forum
6 answers
255 views

I am getting an invalid template error when I am creating a ListView in which the Editor Template contains a select list that is bound to a datasource that contains elements with an apostrophe.  It looks like the text is getting escaped, as the error message shows it being created as "<option value="Conveners&#x27; Corner (New)">Conveners&#x27; Corner (New)</option>", but I don't know if it's Kendo doing the escaping or MVC or something else.  This encode contains a # sign though, and that doesn't get escaped, which causes the error.

Is this a bug with the ListView control?  Is there some other event where I can escape the escaped text to put a \\ before an # characters?

Miguel Angel
Top achievements
Rank 1
 answered on 12 Feb 2019
4 answers
453 views
Hello,

I'm trying to display a list of checkbox items inside of a list view ONLY if the boolean isSelected field is false.

Here is how I call the listview:
@(Html.Kendo().ListView<TestMultiSelect.ViewModels.TestVM>(Model)
        .Name("listView")
        .TagName("div")
        .ClientTemplateId("template")
        .DataSource(dataSource => dataSource
            .PageSize(20)
            .ServerOperation(false)
         )
        )

My TestView model:
public class TestVM
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public bool IsSelected { get; set; }
    }


..and here is my Client template:

<script type="text/x-kendo-tmpl" id="template">
    <div class="product">
        # var isSelected =  @#:IsSelected#;
        if (isSelected !== true) { # @(Html.Kendo().CheckBox().Name("#:ID#").Label("#:Name#"))  # } #
    </div>
</script>

I get a failure in the client template.

Any suggestions are appreciated.

Thanks in advance,
Dave
Hernu
Top achievements
Rank 1
 answered on 03 Oct 2018
2 answers
593 views

Hi guys,

I think I'm lacking some sort of fundamental knowledge of either Kendo UI or MVC itself. I have a fairly simple example which hopefully you can recreate and explain where I'm going wrong. Before I get to the code I'll explain what I'm trying to accomplish:

I have a form which will be used to capture details as you would normally expect. Inside this form I have a list view, the purpose of which is to allow the user to create and display information about an unspecified number of people. When it comes to saving these details I need the "Base" information to be saved first so that it is given an appropriate Id, after which I can then save the party details which would would of course reference this newly created id.

I'm trying to implement this as follows:

Classes

public class DemoPartyDetails
    {
        public int id { get; set; }
        public string firstName { get; set; }
        public string surname { get; set; }
 
        public DemoPartyDetails()
        {
 
        }
    }

 

public class DemoClass
    {
        public int id { get; set; }
        public string randomData { get; set; }
 
        public List<DemoPartyDetails> partyDetails { get; set; }
 
        public DemoClass()
        {
            partyDetails = new List<DemoPartyDetails>();
        }
    }

 

Controller

public class DemoController : Controller
    {
        // GET: Demo
        public ActionResult Index()
        {
            DemoClass demo = new DemoClass();
            DemoPartyDetails party = new DemoPartyDetails();
            party.firstName = "Test Name";
            party.surname = "Test Surname";
 
            demo.partyDetails.Add(party);
 
            return View(demo);
        }
 
[HttpPost]
        public ActionResult Create(DemoClass model)
        {
            try
            {
                if (model.partyDetails != null)
                    Console.WriteLine("Party details populated");
                else
                    Console.WriteLine("Something went wrong...");
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
}

 

View

@model DemoPortal.Models.DemoClass
 
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
</head>
<body>
@using (Html.BeginForm("Create", "Demo", FormMethod.Post))
{
    <div>
    @Html.EditorFor(model => model.randomData)
    </div>
 
    <div>
        <a class="k-button k-button-icontext k-add-button" href="#"><span class="k-icon k-i-add"></span>Add Party</a>
        @(Html.Kendo().ListView(Model.partyDetails)
                    .Name("demoListView")
                    .TagName("div")
                    .ClientTemplateId("demoTemplate")
                    .DataSource(dataSource => dataSource
                        .Model(model => model.Id(x => x.id))
                        )
                    .Editable(editable => editable.TemplateName("DemoPartyDetails"))
        )
    </div>
 
    <input type="submit" value="Submit" />
}
</body>
</html>
 
 
<script type="text/x-kendo-tmpl" id="demoTemplate">
    <div class="demoParty">
        <h3>#:firstName#</h3>
        <span>#:surname#</span>
    </div>
</script>
 
 
<script>
$(function() {
        var listView = $("#demoListView").data("kendoListView");
 
        $(".k-add-button").click(function(e) {
            listView.add();
            e.preventDefault();
        });
});
</script>

 

Editor Template

@model DemoPortal.Models.DemoPartyDetails
 
@using (Html.BeginForm())
{
    <div>
        @(Html.HiddenFor(model => model.id))
        @(Html.EditorFor(model => model.firstName))
        @(Html.EditorFor(model => model.surname))
 
        <div class="btnArea">
            <a class="k-button k-update-button" href="\\#"><span class="k-icon k-update"></span></a>
            <a class="k-button k-cancel-button" href="\\#"><span class="k-icon k-cancel"></span></a>
        </div>
    </div>
 
}

 

The view displays the pre-populated party data correctly which I guess implies that it has bound to the model correctly. However upon submitting the form the partyDetails list is null. The randomData string is populated correctly with whatever I entered, but I cannot figure out how to pass the partyDetails back to the controller.

I've done a bit of googling and found people sometimes struggle to pass IEnumerables to the controller, but all examples of the solutions do not involve the KendoUI and as such I struggle to implement them.

Any assistance would be greatly appreciated.

Many thanks

Marc

Marc
Top achievements
Rank 1
 answered on 03 Oct 2018
1 answer
280 views

I'm not sure what control or group of controls would best be used to accomplish the following:

 

I need a page for reviewing submitted images(look similar to a carousel)
- At any given time a Reviewer may have 1000 images to review.  They can either skip(arrow right), accept(button) or reject(button).
- If they skip, it should go to the next image
- Once they have skipped any images they should be able to go back(arrow left)
- If they accept or reject, it should remove that image from the queue and go to the next image

- A page with a control to view a single image, description and name
- Buttons for accept and reject
- Left and Right arrow buttons to advance or go back(to skipped images only)
- At any given time there may be 1000 images to review so we don't want to hold them all in memory or go to the database for each one...maybe get 10 at a time and when we have zero go get 10 more?

Preslav
Telerik team
 answered on 21 Sep 2018
5 answers
285 views

Hello, I am trying to set the pagesize of my listview on the client side and I am unable to figure out how to do it. I bound the databound event to a javascript function and I am trying to set the pageSize using "listview.dataSource.pageSize(5)"  but when I call this function once it keeps getting called over and over in a  loop until the stack runs out of room. It does set the pagesize but it shouldn't keep getting called. What am I doing wrong?

Viktor Tachev
Telerik team
 answered on 17 Apr 2018
3 answers
564 views

Hey! i am using telerik listview Template for asp.net MVC i want to filter data from server side i.e i enter data in textbox send to action method and filter data and than pass to again view and bind data to listview initially my listview working perfect all data come through database here is my Code

<script type="text/x-kendo-tmpl" id="template">
    <div class="col-md-8  jumbotron">
        <div class="col-sm-4">
            <span><b>Name:</b></span><br />
            <span><b>Gender:</b></span><br />
            <span><b>DOB:</b></span><br />
            <span><b>Country:</b></span><br />
            <span><b>Province:</b></span><br />
            <span><b>Interset:</b></span><br />
        </div>
        <img img src="#:Image#" width="100" height="100" />
        <div class="col-sm-4">
            <span>#:FirstName#</span><br />
            <span>#:Gender#</span><br />
            <span>#:DOB#</span><br />
            <span>#:CountryName#</span><br />
            <span>#:ProvinceName#</span><br />
            <span>#:Interset#</span><br />
        </div>
    </div>
</script>

<div class="demo-section k-content wide">
    @(Html.Kendo().ListView<Assignment.Models.StudentViewModel>()
                .Name("ListView")
                .TagName("div")
                .ClientTemplateId("template")
                .DataSource(dataSource => dataSource
                .ServerOperation(true)
                .Read(read => read.Action("Get", "Home")
                )
                )
    )
</div>

// here im getting data from server for first load using store procedure now i need to filter data from server side in action method 

public JsonResult Get([DataSourceRequest] DataSourceRequest request)
        {
            var studentData = db.sp_GetStudentData().Select(list => new StudentViewModel
            {
                FirstName = list.FirstName,
                Gender = list.Gender,
                DOB = list.DOB.Value.ToShortDateString(),
                Image = list.Image,
                CountryName = list.Name,
                ProvinceName = list.ProvinceName,
                Interset = list.Interset
            }).ToList();
            return Json(studentData.ToDataSourceResult(request));
        }

Stefan
Telerik team
 answered on 22 Nov 2017
3 answers
934 views

I'm using HTML helper list view. I'm not getting loading image or loading message while loading the Items in the listview HTML helper. Also, how to display "No items to display" message when the listview is empty. Below is the code that I have

 
   <div class="col-sm-12 k-content wide">
        @(Html.Kendo().ListView<CNO.CA.MemberPortal.Web.UI.Viewmodels.DocumentManagementModel>(Model.document)
            .Name("DocumentslistView")
            .TagName("div")
            .ClientTemplateId("template")
            .DataSource(datasource => datasource
            .Read(read => read.Action("GetDocumentsByPersonId", "Profile"))
            .Model(m => m.Id("ID"))
            .ServerOperation(false)
            .PageSize(10))
            .Pageable()                    
             )
)
    </div>

Stefan
Telerik team
 answered on 21 Aug 2017
1 answer
281 views

I'm having issue for display listview template vertically.

<div class="mainsortable">
      
    @(Html.Kendo().ListView<KendoUI_MVC.ViewModel.Product>()
        .Name("listView")
        .TagName("div")
        .ClientTemplateId("template")
        .DataSource(dataSource =>
        {
            dataSource.Read(read => read.Action("ProductGrid_Read", "ListView"));
          
        })
       
    )

    @(Html.Kendo().Sortable()
        .For("#listView")
        .Ignore(".order")
        .Filter(">div.product")
        .Cursor("move")
        .PlaceholderHandler("placeholder")
        .HintHandler("hint")
    )

</div>

</div>

<script type="text/x-kendo-tmpl" id="template">

    <div class="product">
            <div class="panel panel-default">
                <div class="panel-heading">#=ProductID# #:ProductName#</div>
                <div class="panel-body">
                    <div class="partialsortable">

                        @(Html.Kendo().ListView<KendoUI_MVC.ViewModel.Order>()
                        .Name("OrderlistView_#=ProductID#")
                        .TagName("div")
                        .ClientTemplateId("ordertemplate")
                        .DataSource(dataSource =>
                        {
                            dataSource.Read(read => read.Action("Order_Read", "ListView", new { ProductID = "#=ProductID#" }));
                        })
                                 .ToClientTemplate()
                        )

                        @(Html.Kendo().Sortable()
                        .For("#OrderlistView_#=ProductID#")
                       .Filter(">div.order")
                        .Cursor("move")
                        .PlaceholderHandler("placeholder")
                        .HintHandler("hint")

                                 .ToClientTemplate()
                        )

                    </div>
                </div>
            </div>
        </div>

</script>

<script type="text/x-kendo-tmpl" id="ordertemplate">

    <div class="order">
        Unit Price : #:UnitPrice#<br />
        Quantity : #:Quantity#<br />
        Discount : #:Discount#
    </div>

</script>

<script>

    function placeholder(element) {
        return element.clone().addClass("placeholder");
    }

    function hint(element) {
        return element.clone().removeClass("k-state-selected");
    }
    
</script>

<style>
     .mainsortable {
        min-width: 1120px;
    }
    
     .order {
        margin: 10px;
        padding: 10px;
        border: 2px solid #000;
    }

    .panel{
        margin-left:10px;
        margin-right:10px;
        
    }

    .tabstrip{
        margin-bottom:10px;
    }

    .frame{
        padding:10px;
    }

    #listView {
        padding: 10px 5px;
        margin-bottom: -1px;
        min-height: 400px;
        min-width:1120px;
    }

    .product {
        float: left;
        position: relative;
        width: 400px;
        min-height: 100px;
        cursor: default;
    }

    .k-listview:after {
        content: ".";
        display: block;
        height: 0;
        clear: both;
        visibility: hidden;
    }

</style>

In css, #listView  min-width and max-width property does not working properly.

I'm try to set

 .mainsortable {
        width: 5000px;
    }

and

 #listView {
        padding: 10px 5px;
        margin-bottom: -1px;
        min-height: 400px;
        width:5000px;
    }

seperately and it's working prperly.but its not expectable solution because can't adjust the width.

I attached following the screenshot of expected listview (Expected.png) and Issued listview (Issue.png).

Please give explanation for this issue.

Stefan
Telerik team
 answered on 02 Aug 2017
2 answers
437 views

How can I specify the id of the record as an optional parameter in the UrlAction?

@model IEnumerable<proITdesk.Database.Models.Address>

...

<script type="text/x-kendo-tmpl" id="template">

    <a href='@Url.Action("Details", "Addresses", new { Id = "#=Id#" }.ToString())'>
        <div class="widget-primary">
            <h4 style="text-align:center">#:Name#</h4>
            <img src="@Url.Content("~/content/web/foods/")#:Id#.jpg" alt="#:Name# Image" />
        </div>
    </a>
</script>     
Harald
Top achievements
Rank 2
 answered on 16 Jul 2017
6 answers
385 views

Below is my view containing my ListView as well as my controller.  I can successfully edit and save my data client side, but it never calls the update action on my controller and I can't figure out why.  I've copied the example from the Editing demo, but can't figure out what I'm missing.  Any ideas?

 

@model IEnumerable<Announcement>
@{
    Layout = "~/Views/Shared/_Kendo.cshtml";
}
<link rel="stylesheet" href="~/lib/kendo-ui-core/css/web/kendo.common.min.css" />
<link rel="stylesheet" href="~/lib/kendo-ui-core/css/web/kendo.default.min.css" />
<script src="~/lib/kendo-ui-core/js/jquery.min.js"></script>
<script src="~/lib/kendo-ui-core/js/kendo.all.min.js"></script>
<script src="~/lib/kendo-ui-core/js/kendo.aspnetmvc.min.js"></script>

 

@(Html.Kendo().ListView<Announcement>(Model)
    .Name("listView")
    .TagName("div")
    .ClientTemplateId("template")
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model => model.Id("Id"))
        .Read(read => read.Action("Index_Read", "ListView"))
        .Update(update => update.Action("Index_Update", "ListView"))
    )
    .Editable()
)
<script type="text/x-kendo-tmpl" id="template">
    <div class="form-group">
        <h4>#:Category#</h4>
        #:Description#
        <div class="text-right">
            <a class="btn btn-xs btn-primary k-edit-button" href="\\#">Edit</a>
            <a class="btn btn-xs btn-primary k-delete-button" href="\\#">Delete</a>
        </div>
    </div>
</script>
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using My.BO;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;
 
namespace Web.Controllers
{
    public class KendoController : Controller
    {
        // GET: /<controller>/
        public IActionResult Index()
        {
            var model = GetAnnouncements();
            return View(model);
        }
 
        public ActionResult Index_Read([DataSourceRequest] DataSourceRequest request)
        {
            return Json(GetAnnouncements().ToDataSourceResult(request));
        }
 
        [AcceptVerbs("Post")]
        public ActionResult Index_Update([DataSourceRequest] DataSourceRequest request, Announcement announcement)
        {
            if (announcement != null && ModelState.IsValid)
            {
                //_service.UpdateHotTopic(topic);
            }
 
            return Json(ModelState.ToDataSourceResult());
        }
 
        private List<Announcement> GetAnnouncements()
        {
            return new List<Announcement>() {
                new Announcement()
                {
                    Id = 1,
                    Category = "Test 1",
                    Description = "Test 1"
 
                },
                new Announcement()
                {
                    Id = 2,
                    Category = "Test 2",
                    Description = "Test 2"
                }
            };
        }
    }
}

Ianko
Telerik team
 answered on 29 Jun 2017
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?