Questions tagged [modelmetadata]

88 questions
3
votes
1 answer

How can I get the metadata of the items in a collection in razor view-engine?

I have a project written in C# on the top on ASP.NET MVC 5 framework. I am trying to decouple my views from my view model so I can make my views reusable. With the heavy use of EditorTemplates I am able to create all of my standard views (i.e…
Junior
  • 11,602
  • 27
  • 106
  • 212
3
votes
2 answers

Problem with MVC ModelMetaData attributes and formatting a Date

I am trying to figure out how to format a date using MVC3 RC2 and a model decorated with DataAnnotations. This is my model... public class Model { [Display(Name = "Date of Birth")] [DisplayFormat(@DataFormatString = "MM/dd/yyyy")] public…
3
votes
1 answer

How should I store metadata in an object?

In my Java application, I store some data in serveral files in a proprietary format. At runtime, the content and some metadata are stored in an object. In my current approach, the class looks like this: An other approach would be to encapsulate…
Franz Deschler
  • 2,456
  • 5
  • 25
  • 39
3
votes
1 answer

ModelMetadata TemplateHint always null

I am trying to create a custom ModelMetadataProvider to provide unobtrusive attributes for the JQuery UI Autocomplete widget. I have a custom attribute that looks like this: [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public…
3
votes
1 answer

ASP.NET MVC - Model's metadata used from model object type instead of declared model of the View

I have interface of a model declared, with class implementing it: public interface IMyModel { [Range(1, 1000)] [Display(Name = "ModelProp From Interface")] int MyIntProperty { get; set; } IMySubModel SubModel { get; } } public…
2
votes
0 answers

How to render a menu with Razor using an Editor-Template?

I have an asp.net core 3.1 based app. I like to utilize Display-Templates and Editor-Templates to create the editor views. I am trying to figure out the best approach on how to create editor templates for menus using editor-templates. My first…
Jay
  • 1,168
  • 13
  • 41
2
votes
0 answers

Tests involving TryValidateModel fail when run with test using custom HtmlHelper

I have a test of an HtmlHelper extension method that works great when it is the only test that I run. It appears below. All of my other unit tests succeed when I run them, as long as I don't run this test at the same time. But when I run this and…
MKP
  • 65
  • 5
2
votes
1 answer

Is there a way to instruct ASP.NET MVC about some class metadata other than putting the MetadataTypeAttribute directly on the class?

Here's a sample of how it works now: [MetadataType(typeof(PersonMetadata))] public class Person { public string Name { get; set; } public int Age { get; set; } } public class PersonMetadata { [Required] public string Name { get;…
Piotr Owsiak
  • 6,081
  • 8
  • 39
  • 42
2
votes
1 answer

ModelMetadata: ShowForEdit property not appearing to work

Iv wrote an MetaDataProvider like the one below and am using it in conjunction with Editor templates. The DisplayName is working correctly, but for some reason the ShowForEdit value it not having any effect. Any ideas? public class…
Dan
  • 29,100
  • 43
  • 148
  • 207
2
votes
1 answer

ASP.NET MVC Custom MetadataProvider

I'm building a custom MetadataProvider and I'd like to access the actuall model value in the CreateMetadata method. public class IcpMetadataProvider : AssociatedMetadataProvider { protected override ModelMetadata…
user137348
  • 10,166
  • 18
  • 69
  • 89
2
votes
1 answer

ModelMetadata.Container property is null

I am writing a custom ModelMetadataProvider which extends default DataAnnotationsModelMetadataProvider. Unfortunately i came across an issue: ModelMetadata.Container property is always null. According to msdn description of ModelMetadata Class,…
Alex Art.
  • 8,711
  • 3
  • 29
  • 47
2
votes
3 answers

ASP.NET MVC / Linq-to-SQL classes: Can I get it to infer readable display names?

If I have a table Orders with fields CustomerID, OrderID and OrderDate, then the "Linq-to-SQL classes" generated class will be called Orders, with members called CustomerID, OrderID and OrderDate. So far so good. However, if I then do…
Gary McGill
  • 26,400
  • 25
  • 118
  • 202
2
votes
2 answers

Getting the attributes of the field in additional EditorTemplate

I want to make additional editor template for the Int32. In it I want to get all attributes(custom/default-data-annotations) and do some work with them: @model Int32 @{ string propertyName = ViewData.ModelMetadata.PropertyName; var…
Maris
  • 4,608
  • 6
  • 39
  • 68
2
votes
0 answers

Modifying model property metadata in HtmlHelper

I am trying to create a custom HtmlHelper that displays a numeric value formatted to a given number of decimal places. My idea is to change the ModelMetadata.DataFormatString property to achieve this. Is it possible to modify the Metadata properties…
2
votes
1 answer

MVC Html Helper: modelmetadata from string expression

I am trying to build an html helper that would have access to modelmetadata. I need both versions of helper to work: from string expression and from lambda expression: Example: public static MvcHtmlString MyLabel(this HtmlHelper html, string…
Dmitry Efimenko
  • 10,973
  • 7
  • 62
  • 79