views:

46

answers:

1

Withing a Silverlight Application, how does one get the ID from the URL when using MVC given the URL in the standard MVC Format {controller}/{action}/{id}

Is there anything MVC specific or does one need to parse this URL 'manually'?

A: 

Well that's simple, either look in Request.Params["id"] or - and that's more ellegant - add a argument with the name "id" to you Controller method (case does not matter).

public void Index(string id) { }

Works even for more complex objects, the MVC does a good job in retrieving the information and matching it to the arguments of the controller method.

public class Data {
  public string ID { get; set; }
}

public void Index(Data data) {
  // data.id should be set
}

Silverlight runs on the client, therefore it cannot access the values on the server. However, the sever can pass the info to the client.

Obalix
Do you mean adding this in the Controller and then specifiy this on the View in the object tag that holds the Silverlight app?
Mark Redman
That would be one way. Another could be storing it on the server, and then silverlight pulling it from there.
Obalix