Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 4 MVC4从控制器添加脚手架视图引发错误_Asp.net Mvc 4 - Fatal编程技术网

Asp.net mvc 4 MVC4从控制器添加脚手架视图引发错误

Asp.net mvc 4 MVC4从控制器添加脚手架视图引发错误,asp.net-mvc-4,Asp.net Mvc 4,我尝试使用脚手架模板从控制器方法添加视图时出错。我选择哪个模板并不重要,我会得到一个错误。我正在使用VS2012更新2 控制器方法和模型为: public ActionResult EditInventoryItem(int id) { InventoryRepository repo = new InventoryRepository(); Inventory inventoryItem = repo.GetSingle(id); return View(

我尝试使用脚手架模板从控制器方法添加视图时出错。我选择哪个模板并不重要,我会得到一个错误。我正在使用VS2012更新2

控制器方法和模型为:

  public ActionResult EditInventoryItem(int id)
  {
     InventoryRepository repo = new InventoryRepository();
     Inventory inventoryItem = repo.GetSingle(id);
     return View(inventoryItem);
  }

    public class Inventory
   {
      public int Id { get; set; }
      public string Number { get; set; }
      public string Description { get; set; }
      public string Category { get; set; }
      public string Group { get; set; }
      public string Manufacturer { get; set; }
      public string ManufacturerModelNumber { get; set; }
   }
我不知道出了什么事。是的,我有对错误消息中提到的程序集的引用。程序集是System.ComponentModel.DataAnnotations、System.core、System.Data.Entity和System.Data.Linq。我只放了四条信息中的一条——太长了

C:\Program Files x86\Microsoft Visual Studio 11.O\Common7JDE\iTenTemplates\CSharp\Web\MVC 4\CodeTemplates\AddView\CSHTML\Details.tt-1,-1:错误:主机在尝试解析程序集引用System.ComponentModel.DataAnnotations时引发异常。转换将不会运行。引发了以下异常:System.NullReferenceException:对象引用未设置为对象的实例。位于System.Reflection.RuntimeAssemby.\u NLOADSSEMBTYNAME文件名、字符串代码库、证据汇编安全性、RuntimeAssembly位置提示、StackScrawMark和stackMark、IntPtr pPrivHostBinder、Boolean throwOnFileNotFound、Boolean forintrospection、Boolean suppressSecurityChecks at System.Reflection.RuntimeAssemblyName文件名、,字符串代码库、证据assemblySecurity、RuntimeAssemblyLocationHint。stackcrawmark&stackMark,IntPtr pPrivHostBinder,布尔throwOnFileNotFound,用于内省的布尔值。Boolean suppressSecurityChecks at System,Reflection.RuntimeAssemblyjnternalLoadAssemblyNameAssemblyName assemblyRef,证据assemblySecurity,RuntimeAssembly reqAssembly,StackScrawMark&stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean ForlNotInspection,布尔suppressSecurityChecks位于System.Reflection.RuntimeAssemblyinternalLoadString assemblyString。证据assemblySecurity、StackScrawMark和stackMark、IntPtr pPrivf lostBinder、System.Reflection.RuntimeAssembly.InternalLoadString assemblyString上的用于自省的布尔值。证据汇编安全、StackScrawMark和stackMark,用于Microsoft.VisualStudio.Web.Mvc.UserLInterface.MvcTextTemplateHost.ResolveAssemblyReferenceString assemblyString在Microsoft.VisualStudio.TextTemplating.Engine.ResolveAssemblyReferenceSiteExtTemplatingEngineHost在Microsoft.VisualStudio.TextTemplating.Engine.ResolveAssemblyReferenceString处的内省

更新:我不能在这里发布图片,所以请链接到下面的属性。更改复制本地并没有改变行为


我必须运行它才能真正看到发生了什么,而且我无法判断您是否列出了程序集或错误代码。但我认为这可能是错误的。欢迎你试试看

    public class InveentoryController : Controller
    {
       InventoryRepository repo = new InventoryRepository(); 

        public ActionResult EditInventoryItem(int id = 0)   
        {         
           Inventory inventoryItem = repo.inventoryItem.Find(id);
               if (inventoryItem == null)
           {
               return HttpNotFound();
           }
           return View(inventoryItem);
        }
    }

我必须运行它才能真正看到发生了什么,而且我无法判断您是否列出了程序集或错误代码。但我认为这可能是错误的。欢迎你试试看

    public class InveentoryController : Controller
    {
       InventoryRepository repo = new InventoryRepository(); 

        public ActionResult EditInventoryItem(int id = 0)   
        {         
           Inventory inventoryItem = repo.inventoryItem.Find(id);
               if (inventoryItem == null)
           {
               return HttpNotFound();
           }
           return View(inventoryItem);
        }
    }

我遇到了完全相同的问题,它与Microsoft Code Digger扩展0.95有关。禁用扩展可以使脚手架过程成功地工作,没有任何错误。

我遇到了完全相同的问题,它与Microsoft Code Digger扩展0.95有关。禁用扩展允许脚手架过程成功地工作,没有任何错误。

点击“添加”视图中的“添加”按钮后,上面的错误消息来自一个模式窗口。今天早上尝试时,我遇到了一个不同的错误:c:\temp\3fyklisp.0.cs5,33:错误CS0234:编译转换:命名空间“System.ComponentModel”中不存在类型或命名空间“DataAnnotations”:是否缺少程序集引用?对于“System.Data”中的“Linq”重复此错误。转到引用,然后右键单击System.ComponentModel.DataAnnotations。转到属性,截图并编辑您的问题。本地副本应设置为False,但有时将其更改为true会有所帮助。当我在System.Web上出现CS0234错误时,我就是这样做的。上面的错误消息来自于点击“添加”视图中的“添加”按钮后的模式窗口。今天早上尝试时,我遇到了一个不同的错误:c:\temp\3fyklisp.0.cs5,33:错误CS0234:编译转换:命名空间“System.ComponentModel”中不存在类型或命名空间“DataAnnotations”:是否缺少程序集引用?对于“System.Data”中的“Linq”重复此错误。转到引用,然后右键单击System.ComponentModel.DataAnnotations。转到属性,截图并编辑您的问题。本地副本应设置为False,但有时将其更改为true会有所帮助。当我在System.Web上出现CS0234错误时,我就这样做了。我在不止一个网站上看到评论说代码挖掘者0.95是罪魁祸首。如果sophokless提供的答案解决了这个问题,请接受。我在不止一个网站上看到评论说CodeDigger 0.95是c 我在这儿。如果sophokless提供的答案解决了这个问题,请接受。