1

I'm trying to get the parameters of specific attribute routed URL on ActionFilterAttribute. For instance I have an action like below:

[Route("/v1/test/{userId}/{udid}")]
public object GetNewObject(int userId, string udid) 

And in action filter attribute the absolute url is coming something like "http://test.example.com/v1/test/1/123-asda-231-asd". However I want to parse these parameters as userId=1 and udid=... within a collection.

Is it possible?

2 Answers 2

2

Anyway I found the answer,

Within RouteData of ControllerContext we may able to retrieve the specified value.

actionContext.ControllerContext.RouteData.Values["udid"]
Sign up to request clarification or add additional context in comments.

Comments

1

[Route("...")] is possible only in MVC 5. I think you want to do something like this

[RoutePrefix("api/users")]
public class UsersController : ApiController
{
    // GET api/users
    [Route("")]
    public IEnumerable<User> Get() { ... }

    // GET api/user/5
    [Route("{id:int}")]
    public Book Get(int id) { ... }

    // POST api/users
    [Route("")]
    public HttpResponseMessage Post(User book) { ... }
}

where each User contains your properties

public class User
{
     int UserId{get;set;}
     string Udid{get; set;} 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.