问题
I want to use the DataAnnotations.DisplayAttribute.Order property to arrange my fields when using the DisplayForModel and EditorForModel methods.
Related question:
Does the DataAnnotations.DisplayAttribute.Order property not work with ASP.NET MVC 2?
I think that I need to use the ASP.NET MVC 2 Futures. But I can't get it to work.
How do I install ASP.NET MVC 2 Futures?
Why are my fields still out of order?
回答1:
Download ASP.NET MVC 2 Futures from CodePlex.
Save its files somewhere in the file system:
C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 2 Futures\
In the project, right-click References and choose Add Reference
Browse to and then select file Microsoft.Web.Mvc.AspNet4.dll
Register the model metadata provider in Global.asax.cs:
protected void Application_Start() { ... ModelMetadataProviders.Current = new DataAnnotations4ModelMetadataProvider(); DataAnnotations4ModelValidatorProvider.RegisterProvider(); }
回答2:
You should just need to download the futures DLL (Microsoft.Web.Mvc.dll), add a reference to it in Visual Studio, and reference the namespace Microsoft.Web.Mvc
Data Annotations are just attributes, so you may not see compiler errors if there is a problem. The attribute will just not work. You should obtain the source for futures and include it in your project, so that you can breakpoint the appropriate attribute servicing code and make sure it is firing.
回答3:
You probably need to register the metadata provider in your global.asax.
DataAnnotations4ModelMetadataProvider.RegisterProvider();
And also, Microsoft.Web.Mvc.AspNet4.dll is the assembly. You can get it from here http://aspnet.codeplex.com/releases/view/41742
来源:https://stackoverflow.com/questions/2998865/how-do-i-install-asp-net-mvc-2-futures