ASP.NET MVC Generic templating and collections -


It is possible to apply a feature to the archive, and then it can be detected when ViewData.Model Metadata Properties ?

I want to implement an attribute in the archive to specify whether the items in the collection should be displayed completely or not. I want this to be done in Object.ascx (which is related to the display of unknown type objects) to determine whether the detail of the level is displayed.

(Please see the templating approach for background on this general background)

For example:

  public class Parents {[SomeAttributeIWantToDetect] Public IList & lt; Child & gt; Children {receive; Set; }} Public class child {public string name {get; Set; } Public string description {get; Set; }}  

object.ascx: (Note, this code belongs to the ASP.NET MVC team, not mine)

   & Lt;% = ViewData.ModelMetadata.NullDisplayText% & gt; & Lt;%} Other {%> & Lt; Table cellpadding = "0" selection = "0" range = "0" & ​​gt; & Lt;% foreach (View Promote) ViewData.ModelMetadata.Properties.Where (pm = & gt; pm.ShowForDisplay & ViewData.TemplateInfo.Visited (pm))) {%> & Lt;% if (prop.HideSurroundingHtml) {%> & Lt;% = HTML Display (prop.PropertyName)%> & Lt;%} Other {%> & Lt; TR & gt; & Lt; TD & gt; & Lt; Div class = "display-label" style = "text-align: right;" & Gt; & Lt;% = prop.GetDisplayName ()%> & Lt; / Div & gt; & Lt; / TD & gt; & Lt; TD & gt; & Lt; Div class = "display-field" & gt; & Lt ;! - ********* here ************************* & Lt;% if (prop.AdditionalValues.ContainsKey (SomeAttributeIWantToDetectAttribute)) Do something else ..... and% & gt; & Lt;% = HTML Display (prop.PropertyName)%> & Lt;%}% & gt; & Lt; / Div & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt;%}% & gt; & Lt;%}% & gt; & Lt; / Table & gt; & Lt;%}% & gt;  

This is not MVC, it is close to classic ASP templates

< P> Which camp do you want to live in, and stay there?

To use MVC, you need to create a villa that expresses the model in the context of a particular render destination

Your view modal should be created using logic commands only from above i.e.

  if (model == empty) {x = ViewData.ModelMetadata.Nul LDisplayText} and {foreach (Viewedata.ModelMetadata.Properties.Where the var prop in Where (pm = & gt; pm.ShowForDisplay & amp;; Amp;; ViewData.TemplateInfo.Visited (pm))) {if (prop hydsurring HTML) {x.Items1.Add (prop.PropertyName)); } Else {prop.GetDisplayName () if (prop.AdditionalValues.ContainsKey (SomeAttributeIWantToDetectAttribute)) {x.Items2.Add ({text = prop.zzz, Highlight = true}); } And {x.Items2.Add ({text = prop.PropertyName})); The code above is clearly wrong, I just try to show that you should take complex codes and arguments and use it to create a view, it should never be visible 

View modal is a simple creation related to the rendering technique you are using (such as html properties etc)

In this view, just want to include simple etterates and layout selectors A Dekenmodel, never the actual model


Comments