Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • SandyK-W 24 posts 64 karma points
    Oct 11, 2024 @ 15:34
    SandyK-W
    0

    TextBoxfor not working with Umbraco 13 models?

    Hi,

    I'm converting an Umbraco 8 site which used to have this code which worked by default:

    <label class="text-input" for="staffName">
        Search by staff name
        @Html.TextBoxFor(a => a.staffName, new { placeholder = "Search for a person e.g. John Smith" })
    </label>
    <label class="select-input" for="SelectedSpecialism">
        Filter by specialism
        @Html.DropDownListFor(a => a.SelectedSpecialism, Model.specialismsDropdown)
    </label>
    <label class="select-input" for="SelectedOffice">
        Filter by office
        @Html.DropDownListFor(a => a.SelectedOffice, Model.officesDropdown)
    </label>
    <input type="submit" value="Search" class="btn" />
    

    But in my new code this is throwing an error about dynamic items and can't see the model for some reason. The error is "An expression tree cannot contain a dynamic operation"

    Any help is much appreciated, I've worked out most other little bugs but this one is beyond me.

  • Marc Goodson 2157 posts 14435 karma points MVP 9x c-trib
    Oct 14, 2024 @ 13:05
    Marc Goodson
    0

    Hi SandyK-W

    What is the underlying class for your Model?

    Model.specialismsDropdown - should contain the dropdown options - but that lowercase letter at the start - makes me think it might be somehow 'dynamic' ??

    What is in the @Model or @inherits statement at the top of the view?

    and can you post what that class looks like?

    The dropdown options passed into DropDownListFor helper needs to be of type List<SelectedListItem>

    regards

    marc

    regards

    Marc

  • SandyK-W 24 posts 64 karma points
    Oct 15, 2024 @ 09:00
    SandyK-W
    0

    Hi Mark,

    Thanks for replying!

    My using/inherits statements:

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.StaffListing>;
    @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
    @using Umbraco.Cms.Core.DependencyInjection;
    

    and here is the extended model class:

    using Microsoft.AspNetCore.Mvc.Rendering;
    using Galbraithv13v2.Extensions;
    
    namespace Umbraco.Cms.Web.Common.PublishedModels
    {
        public partial class StaffListing
        {
            public List<StaffProfile> StaffProfiles;
            public int totalPages; //Total pages that will be made from query result
            public PaginationData paginationData;
            public string SelectedSpecialism;
            public string SelectedOffice;
            public string staffName;
            public List<SelectListItem> specialismsDropdown;
            public List<SelectListItem> officesDropdown;
        }
    }
    

    As I mentioned above this worked fine in v8 but I can't seem to think of a solution for the v13 site. (Might be a lack of experience rather than something complex)

    Thanks, Sandy

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies