I've just ran into a big gotcha with upgrading an ASP.Net MVC app from 3.5 to 4.0. The following code works fine in 3.5, but when run in 4.0 fails with the error below:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Estam.Web.Models.Account.SupplierBuyerViewModel>>" %>
<ul><%
foreach (var buyer in Model)
{
%><li>
<%if (buyer.CanFeedback)
{ %>
<a href="#" class="rateButton rateBuyer" name="<%=buyer.BuyerName%>" id="id_<%=buyer.BuyerId %>">
Rate</a>
<%} %>
<%=buyer.BuyerName%>
</li>
<%
}
%>
</ul>
The error:
Unable to create a constant value of type开发者_如何学JAVA 'Estam.Models.BuyerModel'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
Any help would be greatly appreciated.
PS. Here's the Model code
using System;
namespace Estam.Web.Models.Account
{
public class SupplierBuyerViewModel
{
public Guid BuyerId { get; set; }
public string BuyerName { get; set; }
public bool CanFeedback { get; set; }
public string PrimaryContactEmail { get; set; }
public double Variance { get; set; }
}
}
I think this is an Entity Framework error, so you need to go back to your database model or data access code.
Are you trying to cast an enum inside a Linq-to-Entities query? If so, try to cast it outside the query, if you can.
精彩评论