我正在尝试使用 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);
}
}
这是表单存储库:
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 视图有关还是其他原因?请帮忙!在这个阶段我想做的就是GetAll()
返回存储在 Couchbase 中的所有文档,但是一旦我这样做localhost/forms
就会抛出这个错误。