0

I am trying to use the EditorFor template with a dynamic view

my view looks like

@model dynamic
.....
.....
<div class="form-group">
    @Html.LabelFor(x => x.AddressLine1, new { @class = "control-label" })
    <div class="input-field">
         @Html.TextBoxFor(x => x.AddressLine1, new { @class = "form-control" })
    <div class="help-block with-errors">
         @Html.ValidationMessageFor(x => x.AddressLine1)
    </div>
    </div>
</div>

But I am running into the error

CS1963 An expression tree may not contain a dynamic operation

Is it possible to use editorfor templates with dynamic views ? If so how could I get this to work

thanks

level_zebra
  • 1,503
  • 6
  • 25
  • 44
  • 1
    You could perhaps use `object` instead - see http://stackoverflow.com/questions/11486286/asp-net-mvc-3-editor-for-dynamic-property – James P Oct 27 '16 at 20:57

1 Answers1

0

This issue is passing a dynamic to EditorFor, in the first place. As the error says, expression trees can't work with dynamic objects, and all the *For helpers work with expression trees.

Also, working with a dynamic in an editor template makes no sense, anyways. The whole point of an editor template is to provide a standard view for known types. It's not clear what you're actually trying to do, but I would suggest backing up and asking about the actual problem you're trying to solve, rather than your proposed solution to that problem.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444