DropDownListFor doesn't appear when imported as partial view

0 Answers 98 Views
DropDownList
kva
Top achievements
Rank 2
Iron
Iron
Iron
kva asked on 07 Aug 2023, 11:12 AM

This is partial view:

@model DMDPace.DataAccess.DomainModels.Department

@(Html.Kendo().DropDownListFor(m => m)
    .DataTextField("Name")
    .DataValueField("Id")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetDepartments", "Home");
        });
    })
    )

That's how I reference it:

<div><partial model="@Model.Department" name="Selectors/Department"/></div>
Why doesn't it appear?
Mihaela
Telerik team
commented on 09 Aug 2023, 02:19 PM

Would you try to set the nested Model property to which the DropDownList should bind?

For example:

@model DMDPace.DataAccess.DomainModels.Department

@(Html.Kendo().DropDownListFor(m => m.DepartmentId)
    ...
)

Also, if you remove the DropDownList, does the Partial View load?

kva
Top achievements
Rank 2
Iron
Iron
Iron
commented on 10 Aug 2023, 07:03 AM

I tried to set property, and it appeared, but everything is incorrect. DropDownList appeared in incorrect DOM tree place, input appeared in correct, but it's not hidden and has incorrect id and name attribute's values. Correct are Department, actual are Id.

I got it rendering correctly, writing partial view this way:

@model DMDPace.DataAccess.DomainModels.User

@(Html.Kendo().DropDownListFor(m => m.Department)
    .DataTextField("Name")
    .DataValueField("Id")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetDepartments", "Home");
        });
    })
    )

And using this way:

<partial model="@Model" name="Selectors/Department"/>

But input will have id and name attributes equal Department, which is incorrect, that's need to be DepartmentId. Also, for some reason it doesn't Department's current value, it displays first value of collection returned from the server's endpoint.

Mihaela
Telerik team
commented on 11 Aug 2023, 08:40 PM

I have prepared a demo project based on your scenario. You can find it attached.

Would you please modify it with your code to reproduce the behavior you are experiencing and send it back to me to review it?

Thank you for your cooperation.

No answers yet. Maybe you can help?

Tags
DropDownList
Asked by
kva
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or