.Name inheritance

1 Answer 63 Views
DropDownList
Вадим
Top achievements
Rank 1
Iron
Iron
Вадим asked on 19 Aug 2022, 08:38 PM

The model uses inheritance.How to make that when loading the data from the model is automatically substituted?


@(Html.Kendo().DropDownList()
                    .Name("LoginViewModels.Country.Obl")
                    .HtmlAttributes(new { style = "width:100%" })
                    .OptionLabel("Выберите область")
                    .DataTextField("Key")
                    .DataValueField("Key")
                    .DataSource(source =>
                    {
                        source.Read(read =>
                        {
                            read.Action("LoadObl", "Account");
                        });
                    })
                )

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 24 Aug 2022, 01:45 PM

Hi Vadim,

Thank you for reaching out.

Based on the provided code snippet, I am not entirely certain about the desired outcome that needs to be achieved on your end. That being said could you please share the model structure that is utilized on your end? For example, a code snippet illustrating model hierarchy would be beneficial for the case, as it will give me a better overall understanding of the currently utilized scenario. In addition, could you please elaborate more on what you specifically mean by "How to make that when loading the data from the model is automatically substituted".

Nevertheless, based on the provided label, if the desired result is to insert a value from an inherited property within the model to the .Name() configuration of the DropDownList, I would recommend omitting the "quotation" marks within the name configuration method, so that the model is recognized. Here is an exemplary configuration:

Model Hierarchy:

public class Animal
{
    public int Id { get; set; }
    public string Name { get; set; }

}

public class Dog : Animal
{
        public string Breed { get; set; }
}

View:

@model Dog

@(Html.Kendo().DropDownList()
    .Name(Model.Name)
    ...
)

Controller:

public class HomeController : Controller
{
    public IActionResult Index()
    {
        var dog = new Dog()
        {
            Id = 1,
            Name = "Ruffus",
            Breed = "Pug"
        };

        return View(dog);
    }
}

Would produce the following HTML markup:

That being said, I noticed that there is not a Telerik UI for ASP.NET Core license associated with your account which limits the availability of our support services for the product. In this regard, It is recommended that you either purchase or renew your license in order to gain access to the latest updates, fixes, features, and support regarding the Telerik UI for ASP.NET Core components. More information regarding the currently available plans can be reviewed here:

Support Plans

Kind Regards,
Alexander
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
DropDownList
Asked by
Вадим
Top achievements
Rank 1
Iron
Iron
Answers by
Alexander
Telerik team
Share this question
or