modelmetadata

ModelMetaData, Custom Class Attributes and an indescribable question

扶醉桌前 提交于 2019-12-03 07:36:46
What I want to do seems so simple. In my index.cshtml I want to display the WizardStepAttribute Value So, a user will see at the top of each page, Step 1: Enter User Information I have a ViewModel called WizardViewModel . This ViewModel has a property that is IList<IStepViewModel> Steps each "step" implements the Interface IStepViewModel, which is an empty interface. I have a view called Index.cshtml. This view displays EditorFor() the current step. I have a custom ModelBinder, that binds the View to an new instance of the concrete class implementing IStepViewModel based on the WizardViewModel

MetadataType and client validation in ASP.NET MVC 2

狂风中的少年 提交于 2019-12-01 04:27:04
问题 Inherited properties and MetadataType does not seem to work with client side validation in ASP.NET MVC 2. The validation of our MetadataTypes work as expected on the server but for some reason it does not generate the appropriate client scripts for it. Client side validation kicks in as expected for properties with the DataAnnotations attributes set on the PersonView so I know that client side validation is active and that it works. Does anyone know if or how it can be fixed? Here's what we

Is it possible to override the required attribute on a property in a model?

不羁岁月 提交于 2019-11-29 03:13:26
I'm curious to find out if it is possible to override the [Required] attribute that has been set on a model. I'm sure there most be a simple solution to this problem, any takers? Depends on what precisely you are doing. If you are working with a subclass, using the model with the Required attribute as the base, you can do this: Redefine the property with the new keyword, rather than override it. public class BaseModel { [Required] public string RequiredProperty { get; set; } } public class DerivativeModel : BaseModel { new public string RequiredProperty { get; set; } } If you simply want to

ASP.NET MVC 3 HtmlHelper Exception does not recognize ModelMetadata on inherited interface

梦想的初衷 提交于 2019-11-28 18:23:09
After upgrading to MVC 3 RTM I get an exception where it previously worked. Here is the scenario. I have several objects that use the same underlying interfaces IActivity and IOwned. IActivity implements IOwned (another interface) public interface IActivity:IOwned {...} public interface IOwned { int? AuthorId {get;set;} } I have a partial view that uses IActivity for reuse from other concrete partials. Here is the definition of the Activity Partial. <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IActivity>" %> <%: Html.HiddenFor(item => item.AuthorId) %> However, it throws

Entity Framework - Get Table name from the Entity [duplicate]

[亡魂溺海] 提交于 2019-11-27 21:38:01
This question already has an answer here: Get Database Table Name from Entity Framework MetaData 23 answers I'm using the Entity Framework 4.1 with Code First approach. I'm able to get the storage model types and column names of my entities: var items = context.ObjectContext.MetadataWorkspace.GetItems<EntityType>(DataSpace.SSpace); foreach (var i in items) { Console.WriteLine("Table Name: {0}", i.Name); Console.WriteLine("Keys:"); foreach (var key in i.KeyMembers) Console.WriteLine("\t{0} ({1})", key.Name, key.TypeUsage.EdmType.FullName); Console.WriteLine("Members:"); foreach (var member in i

Technique for carrying metadata to View Models with AutoMapper

北慕城南 提交于 2019-11-27 17:45:20
I use AutoMapper to map my domain objects to my view models. I have metadata in my domain layer, that I would like to carry over to the view layer and into ModelMetadata. (This metadata is not UI logic, but provides necessary information to my views). Right now, my solution is to use a separate MetadataProvider (independently of ASP.NET MVC), and use conventions to apply the relevant metadata to the ModelMetadata object via an AssociatedMetadataProvider. The problem with this approach is that I have to test for the same conventions when binding the ModelMetadata from the domain as I do with my

ASP.NET MVC 3 HtmlHelper Exception does not recognize ModelMetadata on inherited interface

风格不统一 提交于 2019-11-27 11:17:05
问题 After upgrading to MVC 3 RTM I get an exception where it previously worked. Here is the scenario. I have several objects that use the same underlying interfaces IActivity and IOwned. IActivity implements IOwned (another interface) public interface IActivity:IOwned {...} public interface IOwned { int? AuthorId {get;set;} } I have a partial view that uses IActivity for reuse from other concrete partials. Here is the definition of the Activity Partial. <%@ Control Language="C#" Inherits="System

Technique for carrying metadata to View Models with AutoMapper

纵然是瞬间 提交于 2019-11-26 22:37:02
问题 I use AutoMapper to map my domain objects to my view models. I have metadata in my domain layer, that I would like to carry over to the view layer and into ModelMetadata. (This metadata is not UI logic, but provides necessary information to my views). Right now, my solution is to use a separate MetadataProvider (independently of ASP.NET MVC), and use conventions to apply the relevant metadata to the ModelMetadata object via an AssociatedMetadataProvider. The problem with this approach is that

Entity Framework - Get Table name from the Entity [duplicate]

好久不见. 提交于 2019-11-26 20:45:15
问题 This question already has answers here : Get Database Table Name from Entity Framework MetaData (23 answers) Closed 4 years ago . I'm using the Entity Framework 4.1 with Code First approach. I'm able to get the storage model types and column names of my entities: var items = context.ObjectContext.MetadataWorkspace.GetItems<EntityType>(DataSpace.SSpace); foreach (var i in items) { Console.WriteLine("Table Name: {0}", i.Name); Console.WriteLine("Keys:"); foreach (var key in i.KeyMembers)