1

Here's my WebAPI action..

public class AuthenticationController : ApiController { [Route("api/auth/login")] [HttpPost] public object Login([FromBody] LoginViewModel loginViewModel) ... 

How do I generate a URL inside a MVC view?

I've tried this...

@Url.HttpRouteUrl("DefaultApi", new { controller = "Authentication", action= "Login" })" 

... but it says that DefaultApi doesn't exist.

Why does the method want a route name and route parameters?

How did they manage to make routing even more complicated than regular MVC?

What kind of web framework makes requesting a web page / API method / web service thing difficult? Its ridiculous.

1 Answer 1

1

the problem is because you are using attibute routing, so you need to declare the name of the route with the attribute Route, like:

[Route("api/auth/login", Name = "RouteName")] 

And when you use @Url.HttpRouteUrl:

@Url.HttpRouteUrl("RouteName", new { controller = "Authentication", action= "Login" })" 
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.