hi,
i have a controller that has a route
C#
[Route("/book/{Id?}")]hi,
i have a controller that has a route
[Route("/book/{Id?}")]Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Emily FosterRank #3,495 · 415 reputationPosted Mar 7, 2025, 9:26 AM EST
Hello! It looks like you have a controller with a route defined as
[Route("/book/{Id?}")]. This route indicates that the controller is expecting a parameter calledId, which is optional due to the?signifying it's nullable. When a request is made to this route, theIdparameter will be bound from the URL.Model binding is the process of mapping data from an HTTP request to action method parameters in your application. In this case, the
Idparameter in the URL will be bound to the corresponding parameter in your controller method.Validation, on the other hand, ensures that the data being bound is correct and meets certain criteria. You can apply data annotations or custom validation logic to validate the incoming data before further processing.
If you encounter any issues with model binding or need to validate the
Idparameter, you can implement validation logic in your controller or use data annotations in your model to enforce specific rules.Let me know if you need further clarification or examples on how to handle model binding and validation in this context!