VB.Net Late binding operations cannot be converted to an expression tree

被刻印的时光 ゝ 提交于 2019-12-10 21:09:32

问题


I'm getting some VB.Net Late binding operations and getting this error:

Late binding operations cannot be converted to an expression tree.

I've searched here and can only find solutions to the SQL get data code, not to my problem.

At all my x.NAME lines !?

Im new to this so can anyone say me why i get this error..

<div>Navn: <%: Html.EditorFor(Function(x) x.Name)%></div>   

<h3>Adresse</h3>   

<div>Linje 1: <%: Html.EditorFor(Function(x) x.Line1)%></div>   
<div>Linje 2: <%: Html.EditorFor(Function(x) x.Line2)%></div>   
<div>Linje 3: <%: Html.EditorFor(Function(x) x.Line3)%></div>   
<div>Postnr: <%: Html.EditorFor(Function(x) x.Zip)%></div>   
<div>By: <%: Html.EditorFor(Function(x) x.City)%></div>   
<div>Landsdel: <%: Html.EditorFor(Function(x) x.Country)%></div>   

<h3>Tilvalg</h3>   
<label>   
    <%: Html.EditorFor(Function(x) x.GiftWrap)%>   
    Disse vare skal i Gaveindpakning.   
</label>   

回答1:


The problem is that you are trying to use strongly typed helpers like Html.EditorFor while your view is not strongly typed to a class. So you need to indicate the model type in the @Page definition:

<%@ Page 
    Language="VB" 
    MasterPageFile="~/Views/Shared/Site.Master" 
    Inherits="System.Web.Mvc.ViewPage(Of YourApplication.YourModelClass)" %>

Notice how the view is now strongly typed to the model class YourApplication.YourModelClass. Now you can safely use those helper methods:

<%: Html.EditorFor(Function(x) x.Name)%>


来源:https://stackoverflow.com/questions/4237181/vb-net-late-binding-operations-cannot-be-converted-to-an-expression-tree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!