Copied to clipboard

Flag this post as spam?

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


  • Daniel Hursan 4 posts 64 karma points
    Jan 25, 2024 @ 16:56
    Daniel Hursan
    0

    Parameters posting back correctly, locally (macOS) but not on Umbraco Cloud (Windows, same code)

    Hello,

    I created a component which works correctly on my machine (MacOS), but when I deploy code to Umbraco Cloud, parameters are all empty

    This next part works correctly, parameters are there (verified by using some simple hidden inputs which have values)

    @await Component.InvokeAsync(Inventory.ModelTypeAlias, new
      {
        type = type,
        year = year,
        make = make,
        model = model,
        priceRange = priceRange,
        sortBy = sortBy,
        page = page
      });
    

    This next part however, loses parameters (they are all empty) - only on Umbraco Cloud. On my MacOS machine, for some reason, parameters get there correctly

    View Component:

    public async Task<IViewComponentResult> InvokeAsync(
            [FromQuery(Name = "type")] string type,
            [FromQuery(Name = "year")] string year,
            [FromQuery(Name = "make")] string make,
            [FromQuery(Name = "model")] string model,
            [FromQuery(Name = "priceRange")] string priceRange,
            [FromQuery(Name = "sortBy")] string sortBy,
            [FromQuery(Name = "page")] string page,
            CancellationToken cancellationToken = default)
        {
    .... empty params
    

    I can't find any logical reason why parameters would get to the view component on my machine, but not on Umbraco Cloud.

    Need help please.

  • Daniel Hursan 4 posts 64 karma points
    Jan 25, 2024 @ 17:12
    Daniel Hursan
    0

    FYI, when I send parameters to the view component, they are sent like this

    string year = Context.Request.Query["year"].Count > 0 ? Context.Request.Query["year"].FirstOrDefault() : string.Empty;
    ...
    year = year,
    

    Posting the Umbraco Cloud url too, if this helps narrowing down the issue: https://speed-digital-sandbox.useast01.umbraco.io/inventory/

  • Dennis Pedersen 5 posts 136 karma points
    Jan 25, 2024 @ 19:29
    Dennis Pedersen
    0

    Is there a reason you dont create a viewmodel for your data? not sure this helps you in this case - but I personally would always do that.

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Jan 26, 2024 @ 10:22
    Steve Morgan
    0

    Is it possible the url is malformed / parameter values are not properly encoded? Some servers may block urls that have potentially damaging url parameters (think of the old sql injection).

    That might explain why it works locally.

    Try analysing your url to see if there's any characters in there or unencoded entities (spaces, special chars).

  • Daniel Hursan 4 posts 64 karma points
    Jan 26, 2024 @ 10:25
    Daniel Hursan
    100

    Just figured it out. I did a lot of logging to figure out where parameters are lost, and I narrowed it down as a matter of view rendering (parameters were getting correctly to view component, view model was set correctly)

    I removed caching from the way I was invoking my partials and it worked!

    Change from:

    @await Html.CachedPartialAsync("~/Views/Partials/InventoryGridFilters.cshtml", @Model,
      TimeSpan.FromMinutes(60))  
    ...
    

    Changed to

    @await Html.PartialAsync("~/Views/Partials/InventoryGridFilters.cshtml", @Model)
        ...
    
  • Steve Morgan 1349 posts 4459 karma points c-trib
    Jan 26, 2024 @ 10:45
    Steve Morgan
    100

    Ah - I should have thought of this.

    Caching is only enabled on live. The times I've tested things locally - forgetting it's a debug build and then scratched my head on live.

Please Sign in or register to post replies

Write your reply to:

Draft