हो सकता है कि मैं एमवीसी के लिए मॉडल देख रहा हूं और मैं उन्हें करने का सबसे अच्छा तरीका ढूंढ रहा हूं। मैंने अलग-अलग लेखों के भार पढ़े हैं लेकिन कोई भी "सर्वश्रेष्ठ तरीका" के रूप में स्पष्ट नहीं है। अब तक उदाहरण मैं निम्नलिखित गुणों के साथ एक ग्राहक मॉडल हो सकता है:asp.net mvc viewmodels। कितना तर्क (यदि कोई है) में
- प्रथम नाम
- अंतिम नाम
- शीर्षक
- स्थान
कहाँ स्थान एक स्थान के लिए एक विदेशी कुंजी है डेटाबेस में टेबल।
मैं इस ग्राहक को संपादित करने में सक्षम होना चाहता हूं लेकिन केवल पहला नाम, अंतिम नाम और स्थान। मुझे संपादन में शीर्षक के बारे में परेशान नहीं है। तो मेरे विचार में मुझे एक ग्राहक और एक चयनित सूची उत्तीर्ण करने की आवश्यकता होगी।
अब जो मैंने पढ़ा है उससे मेरे पास निम्नलिखित विकल्प हैं (शायद कई और हैं)।
तो मेरा प्रश्न मूल रूप से सबसे अच्छा है?
1)
ViewData["Location"]
करने के लिए एक चयन सूची में जोड़ें और सिर्फ ग्राहक की प्रबलता से टाइप किये दृश्य बनाते हैं?
2)
एक दृश्य मॉडल जहां मैं एक ग्राहक का चयन करें और सूची से पारित बनाएँ (डेटा का उपयोग नियंत्रक में किया जाता है):
public class ViewModelTest
{
public Customer Customer { get; set; }
public SelectList Locations { get; set; }
public ViewModelTest(Customer customer, SelectList locations)
{
Customer = customer;
Locations = locations;
}
}
3)
एक दृश्य मॉडल बनाएं जहां मैं एक ग्राहक और स्थानों की सूची पास करता हूं और दृश्य मॉडल में चयन सूची बना देता हूं।
public class ViewModelTest
{
public Customer Customer { get; set; }
public SelectList Locations { get; set; }
public ViewModelTest(Customer customer, List<Location> locations, string selectedLocation)
{
Customer = customer;
Locations = new SelectList(locations, "LocationID", "LocationName", selectedLocation);
}
}
4)
एक ग्राहक और भंडार दर्रा और देखने मॉडल में डेटा का उपयोग करते हैं।
public class ViewModelTest
{
public Customer Customer { get; set; }
public SelectList Locations { get; set; }
public ViewModelTest(Customer customer, IRepository repository, string selectedLocation)
{
Customer = customer;
Locations = new SelectList(repository.GetLocations(), "LocationID", "LocationName", selectedLocation);
}
}
5)
सिर्फ गुण मैं जरूरत के साथ दृश्य मॉडल बनाएं:
public class ViewModelTest
{
public string FirstName { get; set; }
public string LastName { get; set; }
public SelectList Locations { get; set; }
public ViewModelTest(Customer customer, SelectList locations)
{
FirstName = customer.FirstName;
LastName = customer.LastName ;
Locations = locations;
}
}
6)
या ऊपर से या किसी अन्य तरह के कुछ अन्य संयोजन।
सभी राय स्वागत है।