1

Here's what I want to have:

 [GET("page/{id}/")]
    public ActionResult Execute(Guid id, bool x = false, bool y = false, 
                                         bool z = false)

The reason I want to have the bools optional is so I can later use this method like this:

return RedirectToAction<SomeController>(c => c.Execute(id, y: true));

Unfortunately when I try to build the solution I get these errors: "An expression tree may not contain a call or invocation that uses optional arguments" and "An expression tree may not contain a named argument specification".

My question is: is it possible to do something like that with controllers? What about optional parameters in routing?

1 Answer 1

2

You could use a model class instead. Something like:

public class ExecuteModel
{
    public Guid id {get;set;}
    public bool x {get;set;}
    public bool y {get;set;}
    public bool z {get;set;}
}

and change your Action to:

public ActionResult Execute(ExecuteModel model)
{
   ...
}

and your redirect would become:

return RedirectToAction<SomeController>(c => c.Execute(
    new ExecuteModel{id=id, y=true}));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.