0

I am trying to do a project using the MVC entity framework code first method. I have been following the Microsoft tutorial but with different data to get this far (http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application). I have a person model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace CleryAct.Models
{
    public class Person
    {
        [Key]
        public string rockets { get; set; }
        public bool csa { get; set; }
        public string fname { get; set; }
        public string lname { get; set; }
        public string email { get; set; }

        public virtual ICollection<Session> Sessions { get; set; }
    }
}

And I have a sessions model

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace CleryAct.Models
{
    public class Session
    {

        [Key]
        public int ID { get; set; }
        public string rockets { get; set; }
        public virtual Person Person { get; set; }

        public DateTime training { get; set; }


    }
}

I then created a new scaffolding item under controller for both person and session. I have not done anything to the code auto generated to the view or the controller.cs files. Up to this point it works fine unless I power down my computer. If I turn off my computer the view ends up with errors all over. Deleting both the view and the controller and reading them fixes the problem until I restart my computer and the errors come back. This is an issue because I cannot keep deleting the files and re-adding them. This is my auto generated view code

@model IEnumerable<CleryAct.Models.Session>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Person.fname)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.training)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Person.fname)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.training)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>
    </tr>
}

</table>

Model and Viwebag have an error saying ____ does not exist in current context. Actionlink and DisplayNameFor have the error message 'System.web.webpages.html.htmlhelper' does not contain a definition for ________ and no extention method __________ accepting the first argument type 'system.web.webpages.html.htmlhelper' could be found (are you missing a user directive or an assembly reference). Updating the database does not fix it. A clean and rebuild does not fix it. Starting over with a new database does not fix it (or at least I think I did that right). The only thing that works is completely deleting it and re-adding it. Which only works until the next time I restart my computer. Every autogenerated view has these errors that behave in the same way. Any ideas? web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    </configSections>
  <connectionStrings>
    <add name="CleryContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=CSAdata;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthentication" />
    </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>
</configuration>
Peter O.
  • 32,158
  • 14
  • 82
  • 96
netgen
  • 35
  • 9
  • Sounds like a VS issue. Try deleting your bin and obj folders. Finally, you can try deleting your .suo file. – Steve Greene Mar 15 '16 at 14:50
  • Where can I find the .suo file. I have my show hidden folders turned on. I do not see it listed in visual studio or in my file explorer – netgen Mar 15 '16 at 15:08
  • Same folder as .sln file. Also, see this http://stackoverflow.com/questions/21858199/system-web-webpages-html-htmlhelper-does-not-contain-a-definition-for-actionl – Steve Greene Mar 15 '16 at 15:10
  • Where do I put his I have tried a few places but none of them work. My code for webconfig is above. – netgen Mar 15 '16 at 15:29
  • Also, I deleted the .suo and now I cannot run my project. it it coming up with page con not be dissplayed – netgen Mar 15 '16 at 15:52
  • The suo stores personal info like what startup project you want, so reselect your startup project in solution properties. – Steve Greene Mar 15 '16 at 16:50
  • Put your razor config in the web.config in /Views folder, not the main folder. – Steve Greene Mar 15 '16 at 16:53
  • I set the home/Index.cshtml as that start page and it is still not working. Am I doing something wrong? – netgen Mar 15 '16 at 17:31
  • Set web project as startup in SOLUTION. Then set startup page to blank in the mvc PROJECT and it should follow your default route. – Steve Greene Mar 15 '16 at 17:37
  • Ok, I tried that and it is still not running. Also, I am not sure if it will make a difference but I am still getting the errors as well. – netgen Mar 15 '16 at 17:48
  • FireFox and chrome are saying it is an SSL error – netgen Mar 15 '16 at 18:26
  • Are you hitting the default controller action or the global.asax? What's the error? – Steve Greene Mar 15 '16 at 18:35
  • It has been this same thing since I deleted the .suo I am not sure what you mean by hitting it. I set the start page to the solution and left it blank and it still did not fix anything. And the original error is still there. Browser errors when I try to run the progam are. Chrome ERR_SSL_PROTOCOL_ERROR Firefox ssl_error_rx_record_too_long – netgen Mar 15 '16 at 18:38
  • Check you web server port and ssl enabled setting. Click your web project, press F4 - look for SSL enabled property. – Steve Greene Mar 15 '16 at 19:00
  • I don's know if this helps or not but I created a new project with the same name and deleted the .Suo file from it and put in the one from my current project. It ran just fine. I am not sure if this means anything or not – netgen Mar 15 '16 at 19:02
  • Also, It was a true or false. I made sure it said true. It is still now working – netgen Mar 15 '16 at 19:05
  • What's your IIS Express setting? For example mine is http://localhost:55589/ – Steve Greene Mar 15 '16 at 19:06
  • I am not sure if this is right. Under SSL URL it says https://localhost:44300/ and under URL it says http://localhost:12448/ – netgen Mar 15 '16 at 19:10
  • Scratch that - 44300 is ok – Steve Greene Mar 15 '16 at 19:11
  • Check your system tray and shut down IIS express. – Steve Greene Mar 15 '16 at 19:12
  • I do not think it has been active – netgen Mar 15 '16 at 19:15
  • Do you even need SSL? My settings are off. Also, your solution properties have your MVC project as startup? – Steve Greene Mar 15 '16 at 19:21
  • I think I am supposed to use an LDAP system for login. Did I do something wrong with that startup. I did it and asked someone if I did it right. We both though I went to solution and set it to blank. Also, SSl was originally set to false when you told me to make sure it was enables and I was still getting the error. – netgen Mar 15 '16 at 19:26
  • Thanks for your help. I am just going to restart the project from scratch. I can not figure out how to make it work – netgen Mar 15 '16 at 19:52
  • Yeah, you can cut and paste a bulk of the work. Good luck. – Steve Greene Mar 15 '16 at 20:11
  • Making a new project seemed to fix things. Thanks for the help. – netgen Mar 16 '16 at 19:01

0 Answers0