Reputation: 875
I just changed some code to add a full count of all the wines in my database to a viewmodel. When I copied all the updated files to my server, I keep getting the below error:
'vf2.ViewModels.MyAccountViewModel' does not contain a definition for 'DBWineCount' and no extension method 'DBWineCount' accepting a first argument of type 'vf2.ViewModels.MyAccountViewModel' could be found (are you missing a using directive or an assembly reference?)
This works fine on my dev box, and the files are the same. I edited my web.config files to force a compile, but I still have this issue. If I try using ViewBag instead, it doesn't throw and error - but it returns a blank value. What could be going on here? Below are my code samples:
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>
Upvotes: 0
Views: 132
Reputation: 5247
I suspect you are coming from ASP.NET development where the compiler ran automatically upon first access of a page. In ASP.NET MVC you need to force a compile using Visual Studio's publish command. Right-click the solution and select 'Publish...' , then select the folder you wish to publish the files and then upload the contents of that folder to the production server.
Note that if you are using Entity Framework and on a shared host you may not have the permissions to run the app and have EF automatically create the database for you. In that case you will need to generate the SQL scripts and manually execute these on the database.
Note that modifying the web.config only restarts the application but does not perform any compilation. In ASP.NET MVC you will need to explicitly Build a project to compile in when testing.
Upvotes: 1