2012-03-06 15 views
8

एमवीसी और रेजर का मेरा ज्ञान काफी बुनियादी है इसलिए मुझे उम्मीद है कि यह कुछ आसान है। असल में, मेरे पास Controllers सामान्य है लेकिन मेरे Views फ़ोल्डर में घोंसला वाली संरचना है। उदाहरण के लिए, के बजाय के लिए:नेस्टेड फ़ोल्डर में देखने के लिए एमवीसी कैसे प्राप्त करें

Views -> Index.cshtml 

ऐसा लगता है कि

Views -> BrandName -> Index.cshtml 

मैं इस को हल करने के लिए एक कस्टम सहायक बनाया है, लेकिन मुझे यकीन है कि यह कैसे क्वेरी स्ट्रिंग यूआरएल के साथ काम करेगा नहीं कर रहा हूँ? यहां एक उदाहरण के रूप में एक नियंत्रक है:

private DataService ds = new DataService(); 

    // 
    // GET: /Collections/ 

    public ActionResult Index() 
    { 
     return View(); 
    } 


    // 
    // GET: /Collections/Collection?id=1 
    public ActionResult Collection(int id) 
    { 
     var collectionModel = ds.GetCollection(id); 
     return View(collectionModel); 
    } 

लेकिन यह कैसे मैं ActionResult Collection मिलता है को देखने के लिए:

public static string ResolvePath(string pageName) 
    { 
     string path = String.Empty; 
     //AppSetting Key=Brand 
     string brand = ConfigurationManager.AppSettings["Brand"]; 

     if (String.IsNullOrWhiteSpace(brand)) 
      path = "~/Views/Shared/Error.cshtml"; //Key [Brand] was not specified 
     else 
      path = String.Format("~/Views/{0}/{1}", brand, pageName); 

     return path; 
    } 
+0

अस्पष्ट। आपके पास एक वर्कअराउंड है (जो ज्यादातर काम करता है) लेकिन इसके बजाय एक बहुत सादा नियंत्रक पोस्ट करें? –

+0

@ हेनकहोल्टरमैन मुझे वर्कअराउंड के साथ बहुत अधिक बिंदु नहीं दिख रहा है क्योंकि संभवतः इसे – ediblecode

+0

@HenkHolterman करने का कोई तरीका नहीं है, यह नहीं देखते कि प्रश्न कैसे स्पष्ट नहीं है – ediblecode

उत्तर

12

उपयोग:

Views -> Brand2 -> Collection.cshtml 

यहाँ वैकल्पिक हल विधि मैं उपयोग कर रहा था है निम्नलिखित

public ActionResult Collection(int id) 
{ 
    var collectionModel = ds.GetCollection(id); 
    return View("/Brand2/Collection", collectionModel); 
} 

उपरोक्त कोड निम्नलिखित विचारों को खोजेगा।

~/Views/Brand2/Collection.aspx 
~/Views/Brand2/Collection.ascx 
~/Views/Shared/Brand2/Collection.aspx 
~/Views/Shared/Brand2/Collection.ascx 
~/Views/Brand2/Collection.cshtml 
~/Views/Brand2/Collection.vbhtml 
~/Views/Shared/Brand2/Collection.cshtml 
~/Views/Shared/Brand2/Collection.vbhtml 

या

public ActionResult Collection(int id) 
    { 
     var collectionModel = ds.GetCollection(id); 
     return View("~/Brand2/Collection.cshtml", collectionModel); 
    } 

अब और अधिक प्रत्यक्ष हो सकता है, मैं पहली बार चेतावनी देने के लिए है कि आप इस सवाल का जवाब का उपयोग कभी नहीं, कभी नहीं, कभी नहीं करना चाहिए बनना चाहता हूँ। एक एमवीसी अनुप्रयोग में निहित सम्मेलनों का पालन करने के लिए एक अच्छा कारण है। ज्ञात स्थानों में अपनी फ़ाइलों को रखने से सभी को आपके आवेदन को समझना आसान हो जाता है।

+0

धन्यवाद अच्छा महोदय, और टिप के लिए भी धन्यवाद :) – ediblecode

+0

खुशी मैं – heads5150

+0

मदद से कम लेकिन नौकरी सुरक्षा के लिए +1 मदद कर सकता हूं। – mdlars

संबंधित मुद्दे