Wednesday, June 17, 2015

Glass Editable method not working properly in a loop without a model being explicitly passed to it

Glass documentation states that there are two ways to use the Editable method on Webforms.

<%= Editable(Model, x => x.Title) %>  //explicitly stating the model
    <%= Editable(x => x.Title) %> //using the Model property 

What I noticed is that the second one only works outside of the loop. For example, if I am on a detail page for an article and I need to render the title. But if I am in a foreach to display the article's three authors it displays the same data three times and it happens to be the data for the last item in the collection.

What I needed to do was to use the first method where the Model is explicitly passed.