我只是更改了一些代码,将数据库中所有葡萄酒的完整计数添加到视图模型中。当我将所有更新的文件复制到我的服务器时,我不断收到以下错误:
“vf2.ViewModels.MyAccountViewModel”不包含“DBWineCount”的定义,并且找不到接受“vf2.ViewModels.MyAccountViewModel”类型的第一个参数的扩展方法“DBWineCount”(您是否缺少 using 指令或程序集引用?)
这在我的开发盒上运行良好,文件相同。我编辑了我的 web.config 文件以强制编译,但我仍然有这个问题。如果我尝试改用 ViewBag,它不会抛出错误 - 但它会返回一个空白值。这里会发生什么?以下是我的代码示例:
namespace vf2.ViewModels
{
public class MyAccountViewModel
{
public DistributorUser DistributorUser { get; set; }
public ProducerUser ProducerUser { get; set; }
public RestaurantUser RestaurantUser { get; set; }
public UserObj UserObj { get; set; }
[Display(Name="Email")]
public string MembershipEmail { get; set; }
public string GetFullName()
{
return this.UserObj.FirstName + " " + this.UserObj.LastName;
}
public string sInstitutionTab { get; set; }
public string DBWineCount { get; set; }
}
}
[Authorize]
public ActionResult MyAccount()
{
MyAccountViewModel myAccount = new MyAccountViewModel();
MembershipUser muCurrent = Membership.GetUser(true);
muCurrent = Membership.GetUser(true);
myAccount.UserObj = db.UserObjs.Find(muCurrent.ProviderUserKey);
myAccount.MembershipEmail = muCurrent.Email;
int iDocCount = 0;
int iRevCount = 0;
if (myAccount.UserObj != null)
{
myAccount.DBWineCount = string.Format("{0:n0}",db.Wines.Count());
switch ((UserTypesEnum)myAccount.UserObj.UserTypeID)
{
case UserTypesEnum.Producer:
myAccount.ProducerUser = db.ProducerUsers.Find(muCurrent.ProviderUserKey);
myAccount.sInstitutionTab = "My Producer";
myAccount.ProducerUser.Producer.Wines.ToList().ForEach(w => iDocCount += w.Docs.Count);
myAccount.ProducerUser.Producer.Wines.ToList().ForEach(w => iRevCount += w.Reviews.Count);
<I cut the rest out because it is pretty long>
<div class="lightbox" id="gettingStarted" style="text-align:center;">
<a href="#" class="ui-icon ui-icon-circle-close closer"></a>
<h3 style="margin-top:0px;">Getting Started</h3>
<br />
To get started using the site, search useing the searchbox above or the search
tab on the left.
<br />From there you'll have access to all @Model.DBWineCount wines in our database.
<br />
</div>