Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kendo DropDownList bound to Model in Razor Pages scenario does not render data attributes #5164

Closed
martintabakov opened this issue Jul 9, 2019 · 4 comments

Comments

@martintabakov
Copy link
Contributor

martintabakov commented Jul 9, 2019

Bug report

The data attributes are not rendered for the DropDownlist when bound to Model in Razor Pages.

Reproduction of the problem

View:

@page
@model TelerikAspNetCoreApp12.Pages.IndexModel

<form>
    @(Html.Kendo().DropDownList()
            .Name("fabric")
            .OptionLabel("Select...")
            .DataTextField("Text")
            .DataValueField("Value")
            .BindTo(Model.Data)
            .Filter("contains")
    )
    <input type="submit" />
</form>

Back end:

namespace TelerikAspNetCoreApp12.Pages
{
    public class IndexModel : Microsoft.AspNetCore.Mvc.RazorPages.PageModel
    {
        public List<TestModel> Data { get; set; } = new List<TestModel>();

        public void OnGet()
        {
            for (int i = 1; i <= 100; i++)
            {
                Data.Add(new TestModel() { Text = "product" + i, Value = i.ToString() });
            }
        }
    }
}

Model:

namespace TelerikAspNetCoreApp12.Models
{
    public class TestModel
    {
        [Required(ErrorMessage = "Please select")]

        public string Text { get; set; }

        public string Value { get; set; }
    }
}

Inspect the input field for the DropDownList. It does not have data-val and data-val-required attributes.

Current behavior

The data attributes are not being rendered.

Expected/desired behavior

The data attributes should be rendered.

Environment

  • Kendo UI version: 2019.2.619
  • jQuery version: x.y
  • Browser: [all]

TelerikAspNetCoreApp3.zip

@dmanova dmanova added the jQuery label Jul 15, 2019
@kendo-bot kendo-bot added the FP: Unplanned Sync status with associated Feedback Item label Jul 15, 2019
@nenchef nenchef added the FP: Planned Sync status with associated Feedback Item label Nov 26, 2019
@kendo-bot kendo-bot added FP: In Development Sync status with associated Feedback Item and removed FP: Unplanned Sync status with associated Feedback Item FP: Planned Sync status with associated Feedback Item labels Nov 26, 2019
@veselints
Copy link
Contributor

Closing the issue as it was caused by improper configuration of the project. Below you will find a working project with the latest Kendo version:

InRazorPagesBindTo.zip

@kendo-bot kendo-bot added FP: Completed Sync status with associated Feedback Item and removed FP: In Development Sync status with associated Feedback Item labels Nov 26, 2019
@paulterinho
Copy link

Hi @veselints Could you elaborate on how the configuration was improper? I'm looking at a similar issue.

@veselints
Copy link
Contributor

@paulito-bandito, in the initial project sample the page model does not contain any field that is marked as [Required]. The [Required] attribute is used instead on a property of the model that is used to populate the DropDownList source collection:

[Required(ErrorMessage = "Please select")]
public string Text { get; set; }

Moreover, the DropDownList helper does not point to any property of the model.

If you review the correct sample that I have uploaded in my previous reply:

  • The page model contains a [BindProperty] with [Required] attribute:
[Required]
[BindProperty]
public string KendoDropDownValue { get; set; }
  • The DropDownList helper uses its strongly typed version to define value binding with that model field:
@(Html.Kendo().DropDownListFor(m => m.KendoDropDownValue)

@paulterinho
Copy link

Ahhhh, it's clear now. Thanks a alot for the clarification. That helps a ton!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants