我想BindModel內得到模型,並將其轉換爲在指定的BindingContext一個類型創建:Asp.net MVC模型綁定從具體類型轉換類型爲使用反射
var reportFormTypeName = bindingContext.ValueProvider.GetValue(bindingContext.ModelName + ".TableInputModelTypeName");
Type reportFormType = Type.GetType("MyNameSpace.ViewModels." + reportFormTypeName.AttemptedValue);
var model = (reportFormType)bindingContext.ModelMetadata.Model;
這不會工作然而 - 我猜這是一個簡單的反思,我不能讓我疲憊的大腦理清 - 任何人都有任何線索?
:)
問題wuith,那是我不噸;模型中有bindingContext.ModelMetadata.Model數據了 – iwayneo
@iwayneo,你在做什麼? –
基本上這個:http://stackoverflow.com/questions/6484972/viewmodel-with-listbaseclass-and-editor-templates – iwayneo