ASP.NET MVC 3: เปลี่ยนเส้นทางจากคอนโทรลเลอร์หนึ่งไปยังคอนโทรลเลอร์อื่นและเขียน URL ใหม่

สมมติว่าเรามีตัวควบคุมสามตัว (ASP.NET MVC3):

- NewProductController (view ->index)
- ProductModelController (view ->index(int productid))
- ProductDetailsController (view =>index(int productid, int productModelId))

ผู้ใช้สามารถเลือกผลิตภัณฑ์หรือผลิตภัณฑ์ + รุ่นผลิตภัณฑ์จากมุมมองดัชนีของ NewProductController ขึ้นอยู่กับการเลือก เราจำเป็นต้องเปลี่ยนเส้นทางไปยังมุมมองดัชนีของ ProductModelController หรือ ProductDetailsController โปรดแนะนำฉันว่าต้องทำอย่างไร

อีกครั้งแทนที่จะแสดงชื่อของตัวควบคุมใน URL เราต้องการเขียน URL ใหม่เป็นอย่างอื่น

http://www.myDomain/List of product
http://www.myDomain/List of LG TV

โปรดแนะนำแนวทางที่ดีที่สุดในการทำเช่นนี้ให้ฉัน

ขอบคุณพอล


person Paul    schedule 19.04.2012    source แหล่งที่มา
comment
ฉันรู้สึกว่าคุณควรมีตัวควบคุมผลิตภัณฑ์หนึ่งตัว :(   -  person Jayantha Lal Sirisena    schedule 19.04.2012
comment
ดู stackoverflow.com/questions/6118840/mvc3-and-rewrites / สำหรับการเขียน URL ใหม่ใน asp.net mvc3   -  person Ram Khumana    schedule 19.04.2012
comment
คุณสามารถใช้การกำหนดเส้นทาง   -  person Darin Dimitrov    schedule 19.04.2012


คำตอบ (1)


ใช้ 1 คอนโทรลเลอร์และ 3 มุมมอง เช่นนั้น

ProductsController(int? productid, int? productModelId)
{
    if(productModelId.HasValue){
    //Some code to create model
       return View("Details",Model)
    }
    else if(productid.HasValue){

    //Some code to create model
       return View("ProductModel",Model)
    }


    //Some code to create model
       return View("NewProduct",Model)
}
person Yorgo    schedule 19.04.2012