0

I'm trying to make a api like the OPENBANKPROJECT. Such as /api/banks/{BANK_ID}/atms/{ATM_ID} etc. I guess banks and atm is a different controller

I want get a global (api/Claim/{id}/Detail/[action] i need this {id}) parameter before before [action] initialize (maybe in constructor).

How do i get this {id} before [action] initialize?

    [Route("api/Claim/{id}/Detail/[action]")]
    public class ClaimDetailController
    {
        int _id; // assignment {id} 
        public ClaimDetailController(IClaimDetailService claimDetailService)
        {
           `Need Query Id before execute action`
        }
        [HttpPost]
        public async Task<BaseResponse> ClaimDetailInfoPolicy(ClaimDetailKeyModel model)
        {
            return `codes with _id`;
        }
    }

    public class ClaimDetailKeyModel
    {
        public long FileNo { get; set; }
        public long RecourseNo { get; set; }
    }
4
  • Check this: stackoverflow.com/questions/18248547/… Commented Feb 5, 2020 at 9:50
  • Check my answer here Commented Feb 5, 2020 at 11:02
  • @Alexander its a weired solution :) and i am using [ApiController] atturibute. Do you have any solution with that atturibute? Commented Feb 5, 2020 at 14:05
  • @Alexander that solution is second :) Commented Feb 5, 2020 at 14:34

2 Answers 2

1

Solution was simple :)

[ApiController]
[Route("api/Claim/{claimId}/Detail/[action]/")]
public class ClaimDetailController
{
    [FromRoute(Name = "claimId")] 
    public int Id { get; set; }
    public ClaimDetailController(IClaimDetailService claimDetailService)
    {
      `bla bla`
    }

    [HttpPost]
    public async Task<BaseResponse> ClaimDetailInfoPolicy(ClaimDetailKeyModel model)
    {
        return `codes with Id`
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

@Alexander :) just use FromRoute with property :)
0

Add this id to your request handler.

[HttpPost]
public async Task<BaseResponse> ClaimDetailInfoPolicy(int id, ClaimDetailKeyModel model)
{
    return `codes`;
}

2 Comments

"How do i get this {id} before [action] initialize?"
You've done it already [Route("api/Claim/{id}/Detail/[action]")], just put id as mentioned above, it should work.

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.