2

I have action in controller with ASP.NET MVC 5 attribute routing.

public class HomeController : BaseController
{
  [Route("{srcFileFormat}-to-{dstFileFormat}")]
  public ActionResult Converter(string srcFileFormat, string dstFileFormat)
  {
  }
}

I am trying to create url and always get Null instead of URL. Any suggestion how to use UrlHelper.Action and Attribute Routing together in my case?

@Url.Action("docx-to-pdf", "Home")

1 Answer 1

3

In Url.Action we specify the controller name and action method name, not the routing naming or parameters the way you are trying.

We normally do the following way for getting url for a controller action:

@Url.Action("Converter", "Home")

But as your action method expects two parameters too and you are trying to pass those in, you will need to call it passing the parameters too, like:

@Url.Action("Converter", "Home", new {srcFileFormat ="doc",dstFileFormat="pdf"})

Now it should generate the url like:

localhost:6087/doc-to-pdf
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.