ASP.Net MVC - Use the AdditionalMetadata attribute to pass additional data to the views.

By [)ia6l0 iii

The [AdditionalMetadata] attribute is a powerful feature of MVC 3. You can make use of this attribute and pass additional data that will help you make judgements in scenarios where you need to display/take decisions conditionally. The following example makes it more clear.

We have added the additional attribute called "Private" which defines if the contact name is private or not.

[AdditionalMetadata("Private", "true")]
public string ContactName { get; set; }

You can retrieve the metadata values using the ViewData object as shown below:

object _isPrivate;
ViewData.ModelMetadata.AdditionalValues.TryGetValue("Private", out _isPrivate);

Related FAQs

If you browse your mvc pages, through modern day browsers like Chrome - you will find that there would be additional requests like the ones to the favicon. This is the icon, that appears to the left of the web address in the browser once the page loads.
ASP.Net 4.0 provides the SetSessionStateBehavior method through the HTTPContext Class.
Use the Override versions of the page methods instead of thedefault page methods. This would ensure that the .Net runtime does not have to invoke delegates.
Use the FilePathResult to return a file content as the http response.
This error most widely occurs due to a corrupt temporary asp.net file. You can clean the solution, delete the temporary asp.net files and rebuild your solution.
Use the HtpContext's Request object to determine the Browser name.
ASP.Net MVC - Use the AdditionalMetadata attribute to pass additional data to the views.  (2372 Views)