错误:“网址”名称不会在asp.net MVC3目前情况下存在 [英] Error: The name 'Url' does not exist in the current context in asp.net mvc3

查看:132
本文介绍了错误:“网址”名称不会在asp.net MVC3目前情况下存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加型剃刀的MVC 3视图页面到现有的ASP.NET MVC 3项目的根。
VIEWNAME:TestView.cshtml
我打开上面的文件,并尝试添加code的下面一行观点:

I added a MVC 3 View Page of type Razor to the root of the existing ASP.NET MVC 3 project. ViewName: TestView.cshtml I opened the above file and tried to add the following line of code in the view:

<head>
<link href="@Url.Content("~/Content/Styles/Themes/base/jquery.ui.all.css")" rel="Stylesheet" type="text/css" />
    <title></title>
</head>

有关上述我得到一个错误的行:网址名称不会在目前的情况下存在。
但是,当我试图在家庭或账户文件夹中的视图一样,它正在对我罚款。
任何一个可以帮助我知道我缺少什么?

For the line above I am getting an error: The name 'Url' does not exist in the current context. But when I am trying the same in a view within the Home or Account folder it is working fine for me. Can any one help me to know what exactly I am missing?

推荐答案

这是因为你已经创建的视图页在MVC项目的,而不是在 查看 文件夹中。

This is because you have created the view page in the root of the MVC project rather than in the Views folder.

在浏览文件夹中有一个的web.config 文件,该文件具有以下部分:

In the Views folder there is a web.config file which has the following section:

<system.web.webPages.razor>
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
        <namespaces>
            <add namespace="System.Web.Mvc" />
            ...

在此指定的命名空间用来编译看法这就是为什么你会得到网址不存在的错误消息。

The namespaces specified here are used to compile the views which is why you get the 'Url does not exist' error message.

您可以尝试到的web.config 的内容复制到'web.config文件根,但我不知道这是一个好主意。而这样做之后,你可能会得到一个警告,有注册,但根据<无生成提供href=\"http://stackoverflow.com/questions/11590052/actionmailer-net-stand-alone-there-is-no-build-provider-registered-for-the-exte\">this链接这将完全正常工作。

You could try to copy the contents of the web.config to the 'web.config' root but I'm not sure this is a good idea. And after doing so you may get a warning that there is no build provider registered but according to this link this will work perfectly fine.

我相信,那么你可能需要注册一个新的自定义RazorViewEngine指定新的路径搜索视图作为意见在 Views`文件夹的默认视图引擎搜索

I believe you may then have to register a new custom RazorViewEngine to specify the new paths to search for viewas the default view engine searches for views in theViews` folder.

我不知道,如果你可能需要进行其他任何更改,但除非你需要在根文件夹视图,我会建议你移动你欣赏到查看文件夹,希望让你得到它的工作。

I'm not sure if you may need to make any other changes but unless you need to have Views in the root folder, I would recommend you move your view to the Views folder to hopefully allow you to get it working.

这篇关于错误:“网址”名称不会在asp.net MVC3目前情况下存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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