Aşağıdakileri MVC3 (aspx) .NETFramework 4.0'da kullanıyorum.SelectListItem/güncelleştirme başvuru formu MVC3 4.0 - MVC5 4.5.1/görüntüleme uzantısı yöntemi
görünümü sayfa uzantısı yöntemi:
public static List<SelectListItem> GetDropDownListItems<T>(this ViewPage<T> viewPage, string listName, int? currentValue, bool addBlank)
where T : class
{
List<SelectListItem> list = new List<SelectListItem>();
IEnumerable<KeyValuePair<int, string>> pairs = viewPage.ViewData[listName] as IEnumerable<KeyValuePair<int, string>>;
if (addBlank)
{
SelectListItem emptyItem = new SelectListItem();
list.Add(emptyItem);
}
foreach (KeyValuePair<int, string> pair in pairs)
{
SelectListItem item = new SelectListItem();
item.Text = pair.Value;
item.Value = pair.Key.ToString();
item.Selected = pair.Key == currentValue;
list.Add(item);
}
return list;
}
Kısmi modeli: görünümünde
public static Dictionary<int, string> DoYouSmokeNowValues = new Dictionary<int, string>()
{
{ 1, "Yes" },
{ 2, "No" },
{ 3, "Never" }
};
public static int MapDoYouSmokeNowValue (string value)
{
return (from v in DoYouSmokeNowValues
where v.Value == value
select v.Key).FirstOrDefault();
}
public static string MapDoYouSmokeNowValue (int? value)
{
return (from v in DoYouSmokeNowValues
where v.Key == value
select v.Value).FirstOrDefault();
}
public string DoYouSmokeNow
{
get
{
return MapDoYouSmokeNowValue(DoYouSmokeNowID);
}
set
{
DoYouSmokeNowID = MapDoYouSmokeNowValue(value);
}
}
:
Ben MVC5 .NETFramework 4.5.1 uygulamayı güncellenmiş@Html.ExDropDownList("DoYouSmokeNowID", this.GetDropDownListItems("DoYouSmokeNowValues", this.Model.PersonalSocial.DoYouSmokeNowID, false), this.isReadOnly)
. Öncelikle GetDropDownListItems çözümlenemedim, bu yüzden uzantı modelinden @functions kullanarak görünüme kopyaladım, bu hatayı alıyorum. uzatma görüntülemek görünümleri gibi proje iken, MVC5 çok katmanlı ve ben Alan tabakasında modelleri varken
The type argument for method 'IEnumerable<SelectedItem> ASP._Page_Views_Visit_PhysicalExam_cshtml.GetDropDownListItems<T>(ViewPage<T>, string,,int?,bool)' cannot be inferred from the usage. Try specifying the the type arguments explicity.
Bir başka şey, MVC3 çözüm, tek bir projeydi.
Sorunun nedeni, sayfa görüntüleme uzantı yöntemini neden çözümleyemiyorum?
Önerilerinize minnettarım.
'GetDropDownListItems' yöntemi 2 parametreleri' bool ?, bool bekler:
Yani, aslında yardımcıları yeniden hiçbir çaba göstermeden, ben en azından sen WebViewPage kapalı uzatma yöntemini asmak gerektiğini tahmin ediyorum 'Ama geçen üç dize, bool ?, bool'. –
Haklısınız Stephen, yanlış yöntem yolladım. Soruyu uzantı yöntemiyle ilgili daha fazla ayrıntıyla güncelledim. – hncl
Hata mesajı hala aynı mı? (mantıklı değil). Benim sorum, bu zaten ne yapmak gerekiyordu, ve ne @ Html.ExDropDownList() 'nedir? Bunun hepsi, MVC'nin –