未找到视图“索引”或其主数据或视图引擎不支持搜索的位置

时间:2013-06-26 15:19:02

标签: asp.net-mvc couchbase

我正在尝试使用Couchbase后端构建一个Web应用程序。

所有我想做的就是返回所有“表单”,但我收到此错误 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 View有关,还是其他什么? 请帮忙!我想在这个阶段做的只是GetAll()来返回存储在Couchbase中的所有文档,但是只要localhost/forms它就会抛出此错误。

1 个答案:

答案 0 :(得分:4)

它在Views/Forms文件夹中查找名为Index.cshtml的文件(如果您不使用Razor,则为Index.aspx

它似乎正确地击中了ActionResult(基于它在哪里寻找视图),所以我想你的视图名称是不正确的

如果在已部署的应用上发生这种情况,则构建操作可能不正确且文件未被复制