How do i configure optional flags in MVC 1.0 routes 



حمایت از ما | مشهدهاست

How do i configure optional flags in MVC 1.0 routes


حمایت از ما | مشهدهاست

حمایت از ما | مشهدهاست حمایت از ما | مشهدهاست

حمایت از ما | مشهدهاست
`

How do i configure optional flags in MVC 1.0 routes



asked

6 years ago

viewed

48 times

active

6 years ago


I want to configure a route with optional flags.

E.g. I want to be able to call the products page and send optional filters (flags) for offers and in stock options. If the flags are NOT specified then all products should be returned.

http://localhost/products

http://localhost/products/onlyOnOffer

http://localhost/products/onlyInStock

http://localhost/products/onlyInStock/onlyOnOffer

[AcceptVerbs(HttpVerbs.Get)] public ActionResult GetProducts(bool onlyInStock, bool onlyOnOffer) {     //... } 

How would I configure the route? Is it even possible in MVC 1.0? What about MVC 2.0.


2010-05-06 13:24:41Z


1:


I see 2 ways:

1) Set up 4 different Actions:

   [AcceptVerbs(HttpVerbs.Get)] public ActionResult Index() {     //... }      [AcceptVerbs(HttpVerbs.Get)] public ActionResult IndexOnOffer() {     //... }      [AcceptVerbs(HttpVerbs.Get)] public ActionResult IndexInStock() {     //... }      [AcceptVerbs(HttpVerbs.Get)] public ActionResult IndexInStockAndOnOffer() {     //... } 

2) Send in the 2 parameters in the query string: http://localhost/products/?onlyInStock=false&onlyOnOffer=true

 [AcceptVerbs(HttpVerbs.Get)]     public ActionResult GetProducts(bool? onlyInStock, bool? onlyOnOffer)     {        //...     } 


2:


You're best off using query strings for this. Note that the path is supposed to describe a resource - in this case, the resource that the user wants to get is the products page itself. Attributes like "only in stock" and "only on offer" are modifiers which change only how the resource is displayed to the end user; they don't change the fact that the resource you're getting is the products page.




 اين مطلب بدون دخالت انساني عينا از اين آدرس کپي شده و تمامي مسوليت آن با ناشر اصلي است.

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated
How to get a user's client IP address in ASP.NET?
The breakpoint will not currently be hit. No symbols have been loaded for this document in a Silverlight application
WCF - How to Increase Message Size Quota
How to get current page URL in MVC 3
Why is access to the path denied?

Call a stored procedure with parameter in c#
An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode
How to get current page URL in MVC 3
Read data from SqlDataReader
Get current date only in C#
How to add doublequotes to a string that is inside a variable?
*