简体   繁体   中英

MVC 3 Editorfor template for dynamic property

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM