2013-06-26 57 views
1

我想用Couchbase後端構建一個Web應用程序。未找到'索引'或其主人的視圖或沒有視圖引擎支持搜索的位置

試圖做的所有IM是返回所有的 「形式」,但我得到這個錯誤 The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/forms/Index.aspx ~/Views/forms/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx ~/Views/forms/Index.cshtml ~/Views/forms/Index.vbhtml ~/Views/Shared/Index.cshtml ~/Views/Shared/Index.vbhtml

這裏是我的控制器:

public class FormsController : Controller 
    { 
     public FormRepository formRepository { get; set; } 

     public FormsController() 
     { 
      formRepository = new FormRepository(); 
     } 
     // 
     // GET: /Forms/ 

     public ActionResult Index() 
     { 
      var forms = formRepository.GetAll(); 
      return View(forms); 
     } 
} 

這裏是FormRepository:

public class FormRepository : RepositoryBase<Form> 
{ 

} 

這裏是RepositoryBase:

public abstract class RepositoryBase<T> where T : ModelBase 
    { 
     private readonly string _designDoc; 

     protected static CouchbaseClient _Client { get; set; } 


     static RepositoryBase() 
     {  
      _Client = new CouchbaseClient(); 

     } 

     public RepositoryBase() 
     { 
      _designDoc = typeof(T).Name.ToLower().InflectTo().Pluralized; 
     } 

     public virtual IEnumerable<T> GetAll() 
     { 
      return _Client.GetView<T>(_designDoc, "all", true); 
     } 
    } 

這裏是我的索引:

@model IEnumerable<QuickQuote.Models.Form> 

@{ 
    ViewBag.Title = "Index"; 
} 

<h2>Index</h2> 

<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
<table> 
    <tr> 
     <th> 
      @Html.DisplayNameFor(model => model.FormTitle) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.Type) 
     </th> 
     <th></th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.FormTitle) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Type) 
     </td> 
     <td> 
      @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | 
      @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | 
      @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) 
     </td> 
    </tr> 
} 

</table> 

這裏是我的Global.asax.cs:

public class MvcApplication : System.Web.HttpApplication 
    { 
     public static void RegisterModelViews(IEnumerable<Assembly> assemblies) 
     { 
      var builder = new ViewBuilder(); 
      builder.AddAssemblies(assemblies.ToList()); 
      var designDocs = builder.Build(); 
      var ddManager = new DesignDocManager(); 
      ddManager.Create(designDocs); 
     } 

     protected void Application_Start() 
     { 
      AreaRegistration.RegisterAllAreas(); 

      WebApiConfig.Register(GlobalConfiguration.Configuration); 
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
      RouteConfig.RegisterRoutes(RouteTable.Routes); 
      RegisterModelViews(new Assembly[] { Assembly.GetExecutingAssembly() }); 
     } 
    } 

有什麼事情做的Couchbase認爲我創建或者是別的東西? 請幫忙!我想在這個階段做的是GetAll()返回存儲在Couchbase中的所有文件,但只要我做了localhost/forms它就會引發此錯誤。

+1

我認爲它couchbase AT的不相關所有。在stackoverflow上有一些類似的問題。 [其中之一](http://stackoverflow.com/questions/2269220/the-view-index-or-its-master-was-not-found)。 – m03geek

回答

4

它在尋找一個(如果你不使用剃刀或Index.aspx)稱爲Index.cshtml文件

它似乎正確擊中的ActionResult的Views/Forms文件夾(基於它在尋找的觀點),那麼我可以想象您的視圖名稱不正確,

如果這是在部署應用中發生的,它可能是生成動作是不正確的,該文件不被複制

+0

謝謝你,cshtml必須是這樣的(在我的情況下,在Views/Home目錄中,它不存在,現在是 –

+0

,如果它的構建問題(像我這樣)右鍵單擊.cshtml沒有找到的文件,進入屬性,然後在屬性窗口中將Build Action設置爲'Content'構建你的應用程序並重新部署。如果所有文件都在正確的文件夾中(如上面的答案所述) – Aim

相關問題