Reputation: 713
I searched a lot of questions and no one seems to address my specific problem.
I was reading some tutorials and the [Route("Text")]
is not working as in the tutorials.
So with this code:
public class AboutController
{
public string Copyright() {
return "\u00a9 Copyright are the best";
}
public string Year() {
return "2016";
}
}
I can go to localhost:xxx/about/copyright
and localhost:xxx/about/year
with no problems.
However if I try adding [Route("what")] immediately before the declaration of AboutController
I now can't navigate to localhost:xxx/what/copyright
or localhost:xxx/what/year
.
However if I try this:
[Route("what/[action]")]
public class AboutController
{
[Route("rights")]
public string Copyright() {
return "\u00a9 Copyright are the best";
}
public string Year() {
return "2016";
}
}
I can go to localhost:xxx/what/year
but not to localhost:xxx/what/rights
(or localhost:xxx/what/copyright
for that matter.
So, what am I missing?
Upvotes: 0
Views: 627
Reputation: 16512
When you add [Route("rights")]
to Copyright()
, that is interpreted as localhost:xxx/what/copyright/rights
.
so using your last example:
[Route("what/[action]")]//url is: localhost:xxx/what/someactionname
public class AboutController
{
[Route("rights")]//url is: localhost:xxx/what/copyright/rights --since CopyRight() is the action
public string Copyright() {
return "\u00a9 Copyright are the best";
}
public string Year() { //localhost:xxx/what/year --since Year() is the action
return "2016";
}
}
Upvotes: 1