2

I am trying to build a web app with a Couchbase backend.

All im trying to do is return all "Forms" but I get this error 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

Here is my 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);
        }
}

Here is the FormRepository:

public class FormRepository : RepositoryBase<Form>
{

}

Here is the 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);
        }
    }

Here is my index:

@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>

Here is my 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() });
        }
    }

Is it something to do with the Couchbase View that I have created or is it something else? Please help! All i want to do at this stage is a GetAll() to return all the documents stored in Couchbase but as soon as I do localhost/forms it throws this error.

Mike Barnes
  • 4,217
  • 18
  • 40
  • 64
  • 1
    I think it's not related to couchbase at all. There are some similar questions on stackoverflow. [One of them](http://stackoverflow.com/questions/2269220/the-view-index-or-its-master-was-not-found). – m03geek Jun 26 '13 at 17:10

1 Answers1

4

It's looking in the Views/Forms folder for a file called Index.cshtml (or Index.aspx if you're not using Razor)

It appears to be hitting the ActionResult correctly (based on where it's looking for the view), so I would imagine that your view name is incorrect

If this is happening on a deployed app, it's possible that the Build action is incorrect and that the file isn't being copied

dave clements
  • 1,505
  • 2
  • 13
  • 28
  • Thanks man, indeed, the cshtml has to be that (in my case in the Views/Home directory. it wasnt there, now it is. – real_yggdrasil Oct 31 '13 at 09:38
  • if its a build issue (like it was for me) right click on the .cshtml file that isnt found, go to Properties, and in the properties window set the Build Action to `Content` build your app and redeploy. It should help if all files are in right folder (as explained in the answer above) – iAM Mar 14 '17 at 20:34