我正在尝试构建一个带有 Couchbase 后端的 Web 应用程序。
我想做的就是返回所有“表单”,但我收到此错误
未找到 View “索引”或其主视图,或者没有 View 引擎支持搜索的位置。搜索了以下位置:
〜/ View /表单/Index.aspx
〜/ View /表单/Index.ascx
〜/ View /共享/Index.aspx
〜/ View /共享/Index.ascx
〜/ View /表单/Index.cshtml
〜/ View /表单/Index.vbhtml
〜/ View /共享/Index.cshtml
〜/Views/Shared/Index.vbhtml
这是我的 Controller :
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);
}
}
这是表单存储库:
public class FormRepository : RepositoryBase<Form>
{
}
这是存储库库:
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
它就会抛出此错误。
最佳答案
它会在 Views/Forms
文件夹中查找名为 Index.cshtml
的文件(或者 Index.aspx
如果您不使用 Razor )
它似乎正确命中了 ActionResult(基于它查找 View 的位置),因此我认为您的 View 名称不正确
如果在已部署的应用程序上发生这种情况,则可能是构建操作不正确并且未复制文件
关于asp.net-mvc - 未找到 View 'Index' 或其主视图,或者没有 View 引擎支持搜索的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17324090/