How to combine route name with route parameters

198 views Asked by At

I need to pass Name = XXX to a method that already contains a {YY} parameter.

So I am trying to combine

    [HttpPut(Name = "SomeFunc")]
    public bool SomeFunc()
    {
        return true;
    }

and

    [HttpPut("{abc}")]
    public bool SomeFunc(string abc)
    {
        return true;
    }

So that I have something like this

    [HttpPut(Name = "SomeFunc")("{abc}")]
    public bool SomeFunc(string abc)
    {
        return true;
    }

But I can't quite find the correct syntax to do so. How do you combine parameters like this?

2

There are 2 answers

0
JOSEFtw On BEST ANSWER

It's a bit unclear what you are asking. Is this what you want?

[HttpPut("{abc}", Name = "SomeFunc")]
public bool SomeFunc(string abc)
{
}
2
Camilo Terevinto On

It seems like you want to have a route named SomeFunc that has a route parameter abc, if that's the case, then you should use:

[HttpPut("{abc}", Name = "SomeFunc")]
public bool SomeFunc(string abc)
{
    return true;
}

Notice that the route is a constructor parameter (parameter order matters) while the name is an optional, named parameter (parameter order doesn't matter).