0

I have three overloaded actions with similar routes; Routing is working fine, the problem is with link generation.

The code is similar to this:

[RoutePrefix("Prefix")]
public partial class MyController : Controller
{

    [ActionName("Index"), Route]
    public virtual ActionResult ActionMethod() {}

    [ActionName("Index"), Route("{param1}")]
    public virtual ActionResult ActionMethod(AnEnum param1, long? param2 = null) {}

    [HttpPost, ActionName("Index"), Route("{param1}")]
    public virtual ActionResult ActionMethod(Model model) {}
}

With current routes prefix/, and prefix/EnumVal1 works just fine, the problem is with generated URLs; I get prefix/?param1=Val for second action method, which doesn't route properly, neither does the post action.

If I change their route's order, first link doesn't generate properly.

[ActionName("Index"), Route("", Order = 1)]
public virtual ActionResult ActionMethod() { }

[ActionName("Index"), Route("{param1}", Order = 0)]
public virtual ActionResult ActionMethod(AnEnum param1, long? param2 = null) {}

Any idea what am I missing here? Please note that determining route names explicitly is not possible, since there are external links.

Akbari
  • 2,369
  • 7
  • 45
  • 85
  • How are you generating the links? You have noted `prefix/?params1=Val` but your route does not contain a parameter for `params1` - its `param1` (or is that just a typo in your question) –  Nov 10 '17 at 09:41
  • I use helpers to generate them, that's just a typo. – Akbari Nov 11 '17 at 02:07
  • I should also note that I'm using `T4MVC`. All ActionResults are generated using it, if it might have anything to do with it. – Akbari Nov 11 '17 at 05:24
  • Might be useful to at least how how you have used the Helper in the question –  Nov 11 '17 at 06:09
  • `RedirectToAction(Actions.ActionMethod(AnEnum.Val1))`, `Url.Action(MVC.MyController .ActionMethod(AnEnum.Val1))`. Please let me know if I need to add anything else for further clarification. – Akbari Nov 11 '17 at 07:09
  • Have you tried `RedirectToAction(Actions.ActionMethod).AddRouteValue("param1", AnEnum.Val1)` –  Nov 11 '17 at 07:12
  • Thanks for your suggestion, I just gave it a try and unfortunately it didn't work. – Akbari Nov 11 '17 at 07:24
  • As far as I've tried, it has nothing to do with `T4MVC`; There is something wrong with the routes, since I can see this problem even when using hard-coded strings. – Akbari Nov 18 '17 at 12:57

0 Answers0