0

I have a controller (CarsController). I want to set multiple route to action in this controller. For example;

public class CarsController : Controller
{
     [Route("cars/create")]
     [Route("cars/edit/{id}")]
     public action CreateOrEdit(int? id)
     {
       ...
     }
}

But I can not. What's the problem?

1 Answers1

0

Following code is great work. Thank You Tetsuya Yamamoto..

    [Route("cars/{type:regex(create|edit)}/{id?}")]
    public async Task<ActionResult> CreateOrEdit(long? id)
    {
        await FillViewBag();
        if (id.HasValue)
        {
            return View(await this.Database.Cars.Include(i => i.Files).SingleAsync(id.Value));
        }
        return View();
    }

When using in action

@Url.Action("CreateOrEdit", new { type="create"})