vtortola
vtortola

Reputation: 35905

Generate a URL programmatically using the route information without the request context

I'd like to include a relative URL as parameter in one of my custom validation attributes. Something like:

[RemoteValidation(Url= Html.ActionLink("Index","Home"))]
public class Lalala...

How can I do it?

I know that usually I need the request context in order to generate an URL, but considering it is just a relative one, is there any way I can generate the relative url for an action and controller names?

Thanks.

Upvotes: 1

Views: 542

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038820

Have you considered using the [Remote] attribute instead of writing custom attributes?

[Remote("Index", "Home")]
public string Username { get; set; }

And here's a nice article illustrating it in action.

Upvotes: 2

Related Questions