Error : : An expression tree may not contain a dynamic operation

Topics: Customizing Orchard, Troubleshooting, Writing modules
Nov 18, 2011 at 4:44 PM

Trying to use my Module I built. It compiled fine but when I try to get to the editor/admin side i get this error:

 

Compiler Error Message: CS1963: An expression tree may not contain a dynamic operation

Source Error:

 
Line 12:             
Line 13:   <div class="editor-label">
Line 14:     @Html.LabelFor(model => model.TopicCode)
Line 15:   </div>
Line 16:   <div class="editor-field">

This the code in my editor-cshtml file:

 

@{
    
}

@using Topics.Models




<fieldset>
  <legend>Topics Fields</legend>
            
  <div class="editor-label">
    @Html.LabelFor(model => model.TopicCode)  <<<<-----ERROR
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.TopicCode)
 
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.BrochureDesc)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.BrochureDesc)

  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.URL)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.URL)
  
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.ControlPrice)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.ControlPrice)
 
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.GroupNumber)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.GroupNumber)
  
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.GroupPrice)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.GroupPrice)
  
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.Brand)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.Brand)
  
  </div>
  <div class="editor-label">
    @Html.LabelFor(model => model.Country)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.Country)
  
  </div>


            
</fieldset>

Coordinator
Nov 18, 2011 at 4:46 PM

You need to use a specific ViewModel type like @model MyViewModel, or if it is a dynamic object, cast the value to the correct type, here model => (string)model.TopicCode

Nov 18, 2011 at 4:53 PM

Thanks. I changed it to this. and it worked without a viewmodel.

 

@model Topics.Models.TopicsPart