Angularjs无法找到视图,尝试了我所知道的一切

时间:2015-10-24 11:45:32

标签: asp.net angularjs

我使用visual studio中的ng.Net模板制作了项目,我开始运行,我添加了一个新的ProgramController.cs,Program.cshtml模板,programCtrl.js角度控制器和程序角度模块。

它不起作用。

我在客户端有一个ASP.NET web api和angularjs。

以下是两个示例路线:

    $routeProvider.when('/todomanager', {
    templateUrl: 'App/TodoManager',
        controller: 'todoManagerCtrl'
    });

    $routeProvider.when('/program', {
        templateUrl: 'App/Program',
        controller: 'programCtrl'
    });

他们做后端的事情:

    [HttpGet]
    [Authorize]
    public List<Program> GetPrograms()
    {
        string userId = Request.GetOwinContext().Authentication.User.Identity.GetUserId();
        var currentUser = UserManager.FindById(userId);
        return currentUser.Programs;
        //return db.Programs;
    }

    [HttpGet]
    [Authorize]
    public List<todoItem> GetUserTodoItems()
    {
        string userId = Request.GetOwinContext().Authentication.User.Identity.GetUserId();

        var currentUser = UserManager.FindById(userId);
        return currentUser.todoItems;
    }

第一个工作,第二个给出tpload编译错误(找不到模板视图)

如果我在/ program

中调用它,我可以获得TodoManager视图

但是我无法访问我的program.cshtml。它与TodoManager.cshtml

位于同一文件夹中

我可以提供更多代码,但我不知道哪些,因为它一切正常。

到目前为止,我最接近的猜测是,我无法访问该视图,我被块视图处理程序阻止或视图不存在。

我有访问权限。 如果它是viewblockhandler,它也会阻止TodoManager.cshtml 它存在xD我正在看它..

就像我在计算器上发送4 + 4垃圾邮件一样,它一直在返回5 ..

请,任何事情都被困在2个工作日。

编辑其他代码

//RouteConfig RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "App",
            url: "{url}",
            defaults: new { controller = "Main", action = "Index" }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Main", action = "Index", id = UrlParameter.Optional }
        );


    }

//WebApiConfig Register
public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services
        // Configure Web API to use only bearer token authentication.
        config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

        // Web API routes
        config.MapHttpAttributeRoutes();

        //I chaned the routeTemplate so that methods/services would be identified by their action, and not by their parameters.
        //I was getting conflicts if I had more than one GET services, that had identical parameter options, but totally different return data.
        //Adding the action to the routeTemplte correct this issue.
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{action}/{id}",        //routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }

//blockviewhandler in Web.config
    <handlers>
  <remove name="BlockViewHandler"/>
  <add name="BlockViewHandler" path="*." verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>

编辑:项目结构,我有一个HomeController,在那里返回我的Index.cshtml,我有我的视图应该呈现我的视图。

enter image description here 许多人似乎误解了我的真实问题,我想知道:

如何,todoManager工作,程序没有。

1 个答案:

答案 0 :(得分:1)

当使用ASP.NET MVC,Web API等时,你应该将“每个”视图添加到mvc控制器中,你可能在你的一个控制器中有这样的东西:

public ActionResult TodoManager()
{
   return PartialView();
}

假设您正在关注教程或修改示例,则可能是Controllers/AppController。如果为true,则必须将另一个视图添加为:

public ActionResult Program()
{
   return PartialView();
}