lundi 22 mai 2017

Can I use GlassMapper's 'Editable' on a reflected property?

I have a model that has a bunch of properties on it named Cause1, Cause2... Cause20 and Symptom1, Symptom2... Symptom20

I can reflect the property values easy enough, but it breaks Experience Editor.

Here's how I'm building my property list:

var causeFuncs = new List<Expression<Func<Northwestern.Areas.Northwestern.ViewModels.ServiceLine.Condition, object>>>();

Enumerable.Range(1, 20).ToList().ForEach(i =>
{
    string propName = "Cause" + i;
    var prop = this.Model.GetType().GetProperty(propName);
    string propValue = prop.GetValue(this.Model, null) as string;

    if(!string.IsNullOrEmpty(propValue))
    {
        causeFuncs.Add(x => prop.GetValue(this.Model, null));
    }
});

And here's my markup:

@foreach (var causeFunc in causeFuncs)
        {
        <span itemprop="cause" itemscope itemtype="http://ift.tt/1Lfu6aX">
            <span itemprop="name">@this.Editable(causeFunc)</span>
        </span>
        }

I didn't expect it to work... and it didn't. This is the error in the browser:

<span itemprop="name"><p>Expression doesn't evaluate to a member value(ASP.ABC_Views_ServiceLine_Condition_cshtml+&lt;&gt;c__DisplayClass1+&lt;&gt;c__DisplayClass3).prop.GetValue(value(ASP.ABC_Views_ServiceLine_Condition_cshtml).Model, null)</p><pre>   at Glass.Mapper.Utilities.GetTargetObjectOfLamba[T](Expression`1 field, T model, MemberExpression&amp; memberExpression) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Utilities.cs:line 515
at Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression`1 field, Expression`1 standardOutput, T model, Object parameters, Context context, Database database, TextWriter writer) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\GlassHtml.cs:line 572</pre></span>





Aucun commentaire:

Enregistrer un commentaire