开发者

Can the MVC's parameter list be dynamic?

开发者 https://www.devze.com 2022-12-22 04:26 出处:网络
If: http://mySite/Users/9055 returns a db record where UserID=9055 (via the userCo开发者_StackOverflow中文版ntroller.getUserID method)

If:

http://mySite/Users/9055 

returns a db record where UserID=9055 (via the userCo开发者_StackOverflow中文版ntroller.getUserID method)

And:

http://mySite/Users/Smith 

returns the same record via the userController.getUserName method

Isn't it reasonable to code a controller method that parses the either input?

Seems like a great option to users - the url as a means of navigating - as long as the top-level (controller) is broad yet focused enough (Users, Products, Billing, Reports) how do we parse for (so we can search on) any of several different datatypes?

thx


you can have a string parameter for controller's action and then do int.TryParse to check if it is integer. if not assume that it is string

0

精彩评论

暂无评论...
验证码 换一张
取 消