是在ASP.Net MVC 5项目.cshtml文件角路由模板URL支持? [英] Is angular routing template url support for .cshtml file in ASP.Net MVC 5 Project?

查看:327
本文介绍了是在ASP.Net MVC 5项目.cshtml文件角路由模板URL支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个MVC 5项目。当我使用一个HTML页面在我的看法,它加载网页,但是当我用.cshtml网页它不会加载该视图。出现空白页。

I am working on a MVC 5 project. When I use a html page at my views, it load that page but when I use .cshtml page it is not loading the view. The Blank page appears.

$urlRouterProvider
    .otherwise('/app/dashboard');

$stateProvider            
    .state('app', {
        abstract: true,
        url: '/app',
        templateUrl: 'tpl/app.html'
    })
    .state('app.dashboard', {
        url: '/dashboard',
        templateUrl: 'tpl/app_dashboard.html'
    })

请指导我如何使用CSHTML文件或做的最好办法。

Please guide me how to use cshtml file or the best way to do it.

推荐答案

您不能。

您不能在角路线的模板URL中使用路径来一个.cshtml文件。你可以打开你的浏览器中的.cshtml文件?无权利 ?同样的道理也适用于这里。

You cannot use path to a .cshtml file in your template url of your angular route. Can you open the .cshtml file in your browser ? No right ? The same thing applies here.

解决方法:

.cshtml文件包含服务器端code,渲染它,你需要使用一个控制器和动作。他们将呈现你.cshtml文件。因此,有一个控制器动作的回报,对于您查看和使用URL到控制器的动作在你的角度路线。

.cshtml file contains server side code, to render it you need to use a controller and action. They will render that .cshtml file for you. So have a controller action return that view for you and use the url to the controller action in your angular route.

例如:

state('app.dashboard', {
        url: '/dashboard',
        templateUrl: '/dashboard/index'
     })

public class DashboardController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

P.S:试图和这个工作对我来说

p.s: have tried and this worked for me

这篇关于是在ASP.Net MVC 5项目.cshtml文件角路由模板URL支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆