stephen776
stephen776

Reputation: 9234

Can I have multiple display templates for an object in ASP.NEt MVC 3?

Is it possible to have multiple display templates for the same object in asp.net mvc?

In my situation I have a Comment object. I would like to use DisplayFor to automatically loop throught an IEnumerable in my view and display the proper template for each item. This works great. Now say I have another view where I also need to display a list of comments in the same manner...But I wants these comments to be editable by the user.

So basically, Can I have 2 display templates, one for read-only display and one for editable display(or other similar scenarios)?

Upvotes: 0

Views: 889

Answers (1)

amit_g
amit_g

Reputation: 31250

You are looking for EditorTemplate

You could also specify the templateName in the DisplayFor methods.

Upvotes: 1

Related Questions