Call Autoquery service from razor view

Hi,
First of all thank you for all the work in building this amazing framework :slight_smile:

I am just playing with the razor pages, and i have find out how to call a service from a razor page.
Basically i’m trying to create a form to add a new listing.

i have made a new.cshtml page inside a listings folder and i’m fetching categories from an autoquery service with the following call to populate a select field

var categoriesResponse = await Gateway.SendAsync(new QueryCategories());

The problem i’m having is that in the case the form has an error, when the service call to get categories is executed again after submit it return an empty list.

i have tried to override the auto query with the following service

public class CategoriesService : Service
{
    public IAutoQueryDb AutoQuery { get; set; }

    public object Any(QueryCategories queryCategories)
    {
        var q = AutoQuery.CreateQuery(queryCategories, Request);
        return AutoQuery.Execute(queryCategories, q, Request);
    }
}

What i have noticed that is somehow intercept some values from the form and because of that the sql expression is getting generated is the following and it will output an empty list

FROM "category" WHERE "category"."name" IS NULL AND "category"."id" = :1

What i’m doing wrong?

Thank you

Can you please put together a small stand-alone repro I can run to repro the issue?

Easiest way is to publish a project on GitHub and post the link here.

Yes sorry for being so late but it was a busy day.

I have made a small repro, it create a simple category table with two record.
i have made a simple form page with a call to the autoquery service for category when the page first load categories are shown. after you press submit they dont load because i think i have an input with an id=name which correspond to the field name on category table, in fact if you change the input to any other name it works even after the submit.

https://github.com/nukedbit/autoquery-razor

Right this is because the Gateway Request is using the same IRequest object so if you’re using the same name it in your form it’s treated as a filter on the Query Service as it uses the untyped Request Params.

I’ve updated the behavior so that InProcess Services like Gateway requests doesn’t use implicit IRequest params. This change is available from the latest v5.8.1 on MyGet. Since you already have v5.8.1 installed you’ll need to clear your NuGet packages cache to download the latest version, e.g:

$ nuget locals all -clear

Note: you should always use the same version of ServiceStack for all libraries as your “ServiceStack.Server” package in the razor host project was referencing “5.8.0”.

Also all DTOs inc. your AutoQuery Request DTOs (e.g. QueryCategories) belongs in your ServiceModel project. They’re impl-free so they don’t require any additional dependencies.

Thank you for the quick fix, i did a quick check and its working now.

Yeah i messed the structure on the demo i was rushing it :slight_smile: but i really love how servicestack is easy to separate concerns.