views:

26

answers:

1

I would like to control or customise the output generated by DisplayFor and EditorFor so it doesn't render the default html css tags for example: .......

I would like this to be for all views not just a type or system type? And what is the simplest solution?

Any help would be appreciated.

A: 

You can always create a custom DisplayFor/EditorFor *.asxc file that resides in either Shared/DisplayTemplates or -/EditorTemplates, pass the relevant type to it and just render what you want.

Following article explains it in further details:

Html.DisplayFor Template Helper in ASP.NET MVC 2.0 to render Complex Object

(This introduces the DisplayFor method - EditorFor works exactly the same way)

Shaharyar
That's a good example and the kind of thing I am looking for but it is tied to a specific type i.e your model class. What would be nice if it was generic and could be used for all types? I think an Object.ascx is needed right?
Euston
You could try this. But I'm afraid how you're going about rendering specific things for specific models?e.g. You're passing a Person to that Partial View - How would you know which fields to render and which not? I don't think you'd want to render `id` field if it's related to a database, right?
Shaharyar