如何在 Durandal 中使用 cshtml 文件? [英] How can I use cshtml files with Durandal?

查看:24
本文介绍了如何在 Durandal 中使用 cshtml 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VS2012 上得到了 DurandalJS StarterKit 模板......一切都很好......

I got the DurandalJS StarterKit template on VS2012... All works great...

但在某些视图中,我需要做类似的事情:

But in some views I need to do something like that:

@if (Roles.IsUserInRole("Administrators"))
{
   <p>Test</p>
}

但是,对于 durandal,我的所有视图都是.html"文件...是否可以使用.cshtml"文件来访问此类信息?

However with durandal all my views are '.html' files... Is that possible to use '.cshtml' files to access some information like that?

或者有没有其他方法可以用 durandal 做到这一点?

Or is there any other way to do that with durandal?

初中

推荐答案

是的,您绝对可以将 cshtml 文件与 Durandal 一起使用,并在服务器上利用 Razor.我认为这也意味着你想要 MVC,所以你也可以这样做并使用它的路由.

Yes, you can absolutely use cshtml files with Durandal and take advantage of Razor on the server. I assume that also means you want MVC, so you can do that too and use its routing.

如果你不想要路由,那么你可以在 web.config 中设置 pages.Enabled,正如其他评论所建议的那样.

If you don;t want the routing then you can set the webpages.Enabled in the web.config, as the other comments suggest.

<add key="webpages:Enabled" value="true" /> 

这篇关于如何在 Durandal 中使用 cshtml 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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