-
Notifications
You must be signed in to change notification settings - Fork 17
Transitions
mauricioaniche edited this page Sep 14, 2010
·
5 revisions
You can add hypermedia to any of your resources. To do that you just have to implement the interface IBehaveAsResource. The signature of the method is the following:
void SetRelations(Relations relations)
Obs: You SHOULD make the method virtual.
You might want to add a relation to some action. The following code does that:
public virtual void SetRelations(Relations relations) { relations.Named("pay").Uses<SomeController>().SomeSimpleAction(); }
The code above creates a transition called “pay” and sets it to an action called “SomeSimpleAction”.
Your URL may have some parameters, just like an ID. You can pass it at the moment you are creating the transition. The following code does that:
public virtual void SetRelations(Relations relations) { relations.Named("get").Uses<SomeController>().Get(this.Id); }
This code will actually get the Id and pass it to the Asp.NET MVC Url Generator. If its related route contains this parameter, it will include it in the Url.
You can point a transition to an external link.
public virtual void SetRelations(Relations relations) { relations.Named("about").At("restfulie.caelumobjects.com"); }