Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:55:50+00:00 2026-06-02T22:55:50+00:00

In my view I call Html.EditFor() which triggers a custom editor-template for this datatype.

  • 0

In my view I call Html.EditFor() which triggers a custom editor-template for this datatype. Additionally I pass some Metadata with it (and that’s the part I don’t like):

<% ModelMetadata metaTitle = ModelMetadataProviders.Current.GetMetadataForProperty(null, Model.GetType(), "Title"); %>
<%: Html.EditorFor(x => Model.Title, new { metaData = metaTitle })%>

The passed type (property Title) is of type ‘Translation’. Within the custom editor-template I have to read the passed metadata from the viewData in order to use it:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Translation>" %>
// {...}
if (ViewData["metaData"] != null)
    metaData = (ModelMetadata)ViewData["metaData"];

Is there some way I could access the metadata directly within the custom editor-template? Unfortunately, if I call the following within the editor-template, I won’t get the same metadata-object (where for example the information if the Title-Property is required or not is missing):

ModelMetadata metaData = ModelMetadataProviders.Current.GetMetadataForType(null, Model.GetType());

I would like to avoid to pass the metadata-object on each call…

Thx for any tipps!
sl3dg3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:55:53+00:00Added an answer on June 2, 2026 at 10:55 pm

    I think you’re trying to get the metadata for the actual property for the EditorTemplate.

    You can do this like this (inside the EditorTemplate):

    var metadata = ModelMetadata.FromStringExpression("", ViewData);
    

    “” means for MVC the current property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

behold, a backbone view render call: render: function() { $(this.el).html(this.template({title: 'test'})); //#1 this.renderScatterChart(); return
(Warning: Clueless Rails Newbie!) In my show.html.erb for my albums view, I call a
I have a Main View which call a settings panel in another view with
I originally created an editor template like this @model MyModel var items = //
I have a form which is rendered using html.RenderAction in MVC3. Outside of this
I have a html page ( editor.php ) which contains a lot of html
Whenever I call Html.RenderAction from a Spark view I get a StackOverflowException. If the
I'm trying to return a JSON response from a Django view call via an
I am developing an application that currently has a View Controller (call it ViewControllerX).
I call a View to be presented with the following code: #import infoView.h ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.