CS0103:当前上下文MVC 4.0中不存在名称“url” [英] CS0103: the name 'url' does not exist in the current context MVC 4.0
问题描述
iam初学者使用mvc和iam使用mvc4.0
我收到此错误CS0103:当前上下文中不存在名称'url'
我尝试过:
Layout.cshtml
<!DOCTYPE html>
< html lang =en>
< head>
< meta charset =utf-8/> ;
< title> @ ViewBag.Title - 我的ASP.NET MVC应用程序< / title>
< link href =@ url.Content(〜/ Content / Site.css)rel =stylesheettype =text / css/> - 此行错误
< script src =@ url.Content(〜/ Scripts / jquery-1.8.3.js)type =text / javascript>< / Script>
< script src =@ url.Content(〜/ Scripts / jquery-ui.min.js)type =text / javascript>< / Script>
< link href =@ url.Content (〜/ Content / jquery-ui.min.css)rel =stylesheettype =text / css/>
< link href =@ Url.Content(〜/ Cont ent / site))
rel =stylesheettype =text / css/>
< link href =〜/ favicon.ico rel =快捷图标type =image / x-icon/>
< meta name =viewportcontent =width = device-width/>
@ Styles.Render(〜/ Content / css)
@ Scripts.Render(〜/ bundles / modernizr)
< / head> ;
< body>
< header>
iam beginner to mvc and iam using mvc4.0
Iam getting this error CS0103: The name 'url' does not exist in the current context
What I have tried:
Layout.cshtml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href ="@url.Content("~/Content/Site.css")rel ="stylesheet" type ="text/css"/>--error on this line
<script src ="@url.Content("~/Scripts/jquery-1.8.3.js")" type ="text/javascript"></Script>
<script src ="@url.Content("~/Scripts/jquery-ui.min.js")" type ="text/javascript"></Script>
<link href ="@url.Content("~/Content/jquery-ui.min.css")rel ="stylesheet" type ="text/css"/>
<link href="@Url.Content("~/Content/site"))"
rel="stylesheet" type="text/css" />
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<header>
@ Html.ActionLink(你的徽标在这里,索引,主页)
@Html.ActionLink("your logo here", "Index", "Home")
@ Html.Partial(_ LoginPartial)
< / header>
</header>
@RenderSection(featured,required:false)
@RenderBody()
@RenderSection("featured", required: false)
@RenderBody()
©@ DateTime.Now。年 - 我的ASP.NET MVC应用程序
© @DateTime.Now.Year - My ASP.NET MVC Application
@ Scripts.Render(〜/ bundles / jquery)
@RenderSection(scripts,required:false)
< / body>
< / html>
---------------- ---------
Index.cshtml
@model insertupdatedelete.Models.mobileda
@ {
ViewBag.Title =索引;
布局=〜/ Views / Shared / _Layout.cshtml;
}
索引
@using(Html.BeginForm()){
@ Html.ValidationSummary(true)
mobil eda
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>
-------------------------
Index.cshtml
@model insertupdatedelete.Models.mobileda
@{
ViewBag.Title = "Index";
Layout ="~/Views/Shared/_Layout.cshtml";
}
Index
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
mobileda
@ Html.LabelFor(model => model.MobileID)
@Html.LabelFor(model => model.MobileID)
@ Html.EditorFor(model => ; model.MobileID)
@ Html.ValidationMessageFor(model => model.MobileID)
@Html.EditorFor(model => model.MobileID)
@Html.ValidationMessageFor(model => model.MobileID)
@ Html.LabelFor(model => model.MobileIDd)
@Html.LabelFor(model => model.MobileIDd)
@ Html.EditorFor(model => model.MobileIDd)
@ Html.ValidationMessageFor(model => model.MobileIDd)
@Html.EditorFor(model => model.MobileIDd)
@Html.ValidationMessageFor(model => model.MobileIDd)
@ Html.LabelFor(model => model.MobileName)
@Html.LabelFor(model => model.MobileName)
@ Html.EditorFor(model => model.MobileName)
@ Html.ValidationMessageFor(model => model.MobileName)
@Html.EditorFor(model => model.MobileName)
@Html.ValidationMessageFor(model => model.MobileName)
@ Html.LabelFor(model => model.MobileIMEno)
@Html.LabelFor(model => model.MobileIMEno)
@ Html.Ed itorFor(model => model.MobileIMEno)
@ Html.ValidationMessageFor(model => model.MobileIMEno)
@Html.EditorFor(model => model.MobileIMEno)
@Html.ValidationMessageFor(model => model.MobileIMEno)
@ Html.LabelFor(model => model.mobileprice)
@Html.LabelFor(model => model.mobileprice)
@ Html.EditorFor(model => model.mobileprice)
@ Html.ValidationMessageFor(model = > model.mobileprice)
@Html.EditorFor(model => model.mobileprice)
@Html.ValidationMessageFor(model => model.mobileprice)
@ Html.LabelFor(model => model.mobileManufacured)
@Html.LabelFor(model => model.mobileManufacured)
@ Html.EditorFor(model => model.mobileManufacured)
@ Html.ValidationMessageFor(model => model.mobileManufacured)
@Html.EditorFor(model => model.mobileManufacured)
@Html.ValidationMessageFor(model => model.mobileManufacured)
< br $>
@ Html.LabelFor(model => model.Datetime)
@Html.LabelFor(model => model.Datetime)
@ Html.EditorFor(model => model.Datetime)
@ Html.ValidationMessageFor(model = > model.Datetime)
@Html.EditorFor(model => model.Datetime)
@Html.ValidationMessageFor(model => model.Datetime)
< input type =submit value =创建/>
<input type="submit" value="Create" />
@ Html.ActionLink(返回列表,索引)
@Html.ActionLink("Back to List", "Index")
@section脚本{
@ Scripts.Render(〜/ bundles / jqueryval)
}
--------------------
查看webconfig
< configuration>
< configsections>
< sectiongroup name =system.web.webPages.razortype =System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup,System.Web.WebPages.Razor,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35 >
< system.web.webpages.razor>
< host factorytype =System.Web.Mvc.MvcWebRazorHostFactory,System.Web.Mvc,Version = 4.0.0.0,Culture = neutral, PublicKeyToken = 31BF3856AD364E35>
< pages pagebasetype =System.Web.Mvc.WebViewPage>
< namespaces>
< add namespace =System.Web.Mvc>
< add namespace =System.Web.Mvc.Ajax>
< add namespace =System.Web.Mvc.Html>
< add namespace =System.Web.Optimization>
< add namespace =System。 Web.Routing>
< appsettings>
< add key =webpages:Enabledvalue =false>
< ; system.web>
< httphandlers>
< add path =*verb =*type =System.Web.HttpNotFoundHandler> < br $> b $ b
<! -
在视图页面中启用请求验证将导致在控制器已处理输入后发生验证
。默认情况下,
MVC在控制器处理输入之前执行请求验证。
要更改此行为,请将ValidateInputAttribute应用于
控制器或操作。
- >
< pages>
validateRequest =false
pageParserFilterType =System。 Web.Mvc.ViewTypeParserFilter,System.Web.Mvc,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35
pageBaseType =System.Web.Mvc.ViewPage,System.Web.Mvc ,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35
userControlBaseType =System.Web.Mvc.ViewUserControl,System.Web.Mvc,Version = 4.0.0.0,Culture = neutral, PublicKeyToken = 31BF3856AD364E35>
< controls>
< add assembly =System.Web.Mvc,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35namespace =System.Web.Mvctagprefix =mvc>
< system.webserver>
&l t; validation validateintegratedmodeconfiguration =false>
< handlers>
< remove name =BlockViewHandler>
< add name =BlockViewHandlerpath =*verb =*precondition =integratedModetype =System.Web.HttpNotFoundHandler>
-------------------- -------------
主webconfig
<! -
有关如何配置ASP.NET应用程序的更多信息,请访问
http://go.microsoft.com / fwlink /?LinkId = 169433
- >
< configuration>
< configsections>
<! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >
< connectionstrings>
< add name =myconconnectionstring =数据源= PRABHU-PC; database = welcometesting; integrated security = true;providername =System.Data.SqlClient>
< appsettings>
< add key = 网页:版本值=2.0.0.0>
< add key =网页:已启用value =true>
< add key =PreserveLoginUrlvalue =true>
< add key =ClientValidationEnabledvalue =true>
< add key =UnobtrusiveJavaScriptEnabled value =true>
< system.web>
< compilation debug =truetargetframework =4.0 >
< authentication mode =Forms>
< forms loginUrl =〜/ Account / Logintimeout =2880/> < br $>
< pages>
< namespaces>
< add namespace =System.Web.Helpers >
< add namespace =System.Web.Mvc>
< add namespace =System.Web.Mvc.Ajax>
< add namespace =System.Web.Mvc.Html>
< add namespace =System.Web.Optimization>
< add namespace =System.Web.Routing>
< add namespace =System.Web.WebPages>
< system.webserver>
< validation validateintegratedmodeconfiguration =false>
< modules runallmanagedmodulesforallrequests =true>
< handlers>
< remove name =ExtensionlessUrlHandler-ISAPI-4.0_32bit>
< remove name =ExtensionlessUrlHandler-ISAPI-4.0_64bit>
< remove name =ExtensionlessUrlHandler-Integrated-4.0>
< add name =ExtensionlessUrlHandler-ISAPI-4.0_32bitpath =*。verb =GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONSmodules =IsapiModulescriptprocessor =%windir %\ Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dllprecondition =classicMode,runtimeVersionv4.0,bitness32responsebufferlimit =0>
< add name =ExtensionlessUrlHandler-ISAPI-4.0_64bitpath =*。verb =GET,HEAD,POST,DEBUG,P UT,DELETE,PATCH,OPTIONSmodules =IsapiModulescriptprocessor =%windir%\ Microsoft.NET\Framework64 \v4.0.30319 \ aspnet_isapi.dllprecondition =classicMode,runtimeVersionv4.0,bitness64responsebufferlimit =0>
< add name =ExtensionlessUrlHandler-Integrated-4.0path =*。verb =GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS type =System.Web.Handlers.TransferRequestHandlerprecondition =integratedMode,runtimeVersionv4.0>
< runtime> ;
< assemblybinding xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentassembly>
< ; assemblyidentity name =System.Web.Helperspublickeytoken =31bf3856ad364e35>
< bindingredirect oldversion =1.0.0.0-2.0.0.0newversion =2.0.0.0> < br $>
< dependentassembly>
< assemblyidentity name =System.Web.Mvcpublickeytoken =31bf3856ad364e35>
< bindingredirect oldversion =0.0.0.0-4 .0.0.0newversion =4.0.0.0>
< dependentassembly>
< assemblyidentity name =WebGrease publickeytoken =31bf3856ad364e35>
< bindingredirect oldversion =0.0.0.0-1.6.5135.21930newversion =1.6.5135.21930>
< entityframework>
< defaultconnectionfactory type =System.Data.Entity.Infrastructure.LocalDbConnectionFactory,EntityFramework >
< parameters>
< parameter value =v11.0>
推荐答案
(文件).ready (function(){
(document).ready(function () {
(Datetime)。datepicker();
}); < br $>
< / Script>
("Datetime").datepicker();
});
</Script>
@Html。 ActionLink(返回列表,索引)
@Html.ActionLink("Back to List", "Index")
@section脚本{
@ Scripts.Render(〜/ b undles / jqueryval)
}
--------------------
查看webconfig
< configuration>
< configsections>
< sectiongroup name =system.web.webPages.razortype =System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup,System.Web.WebPages .Razor,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35>
< system.web.webpages.razor>
< host factorytype =System.Web.Mvc.MvcWebRazorHostFactory,System.Web.Mvc,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35>
< pages pagebasetype = System.Web.Mvc.WebViewPage>
< namespaces>
< add namespace =System.Web.Mvc>
< add namespace =System.Web.Mvc.Ajax>
< add namespace =System.Web.Mvc.Html>
< add namespace =System.Web.Optimization>
< add namespace =System.Web.Routing>
< appsettings>
< add key =网页:已启用value =false>
< system.web>
< ; httphandlers>
< add path =*verb =*type =System.Web.HttpNotFoundHandler>
<! -
在视图页面中启用请求验证将导致验证发生
输入已经由控制器。默认情况下,
MVC在控制器处理输入之前执行请求验证。
要更改此行为,请将ValidateInputAttribute应用于
控制器或操作。
- >
< pages>
validateRequest =false
pageParserFilterType =System。 Web.Mvc.ViewTypeParserFilter,System.Web.Mvc,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35
pageBaseType =System.Web.Mvc.ViewPage,System.Web.Mvc ,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35
userControlBaseType =System.Web.Mvc.ViewUserControl,System.Web.Mvc,Version = 4.0.0.0,Culture = neutral, PublicKeyToken = 31BF3856AD364E35>
< controls>
< add assembly =System.Web.Mvc,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35namespace =System.Web.Mvctagprefix =mvc>
< system.webserver>
&l t; validation validateintegratedmodeconfiguration =false>
< handlers>
< remove name =BlockViewHandler>
< add name =BlockViewHandlerpath =*verb =*precondition =integratedModetype =System.Web.HttpNotFoundHandler>
-------------------- -------------
主webconfig
<! -
有关如何配置ASP.NET应用程序的更多信息,请访问
http://go.microsoft.com / fwlink /?LinkId = 169433
- >
< configuration>
< configsections>
<! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >
< connectionstrings>
< add name =myconconnectionstring =数据源= PRABHU-PC; database = welcometesting; integrated security = true;providername =System.Data.SqlClient>
< appsettings>
< add key = 网页:版本值=2.0.0.0>
< add key =网页:已启用value =true>
< add key =PreserveLoginUrlvalue =true>
< add key =ClientValidationEnabledvalue =true>
< add key =UnobtrusiveJavaScriptEnabled value =true>
< system.web>
< compilation debug =truetargetframework =4.0 >
< authentication mode =Forms>
< forms loginUrl =〜/ Account / Logintimeout =2880/> < br $>
< pages>
< namespaces>
< add namespace =System.Web.Helpers >
< add namespace =System.Web.Mvc>
< add namespace =System.Web.Mvc.Ajax>
< add namespace =System.Web.Mvc.Html>
< add namespace =System.Web.Optimization>
< add namespace =System.Web.Routing>
< add namespace =System.Web.WebPages>
< system.webserver>
< validation validateintegratedmodeconfiguration =false>
< modules runallmanagedmodulesforallrequests =true>
< handlers>
< remove name =ExtensionlessUrlHandler-ISAPI-4.0_32bit>
< remove name =ExtensionlessUrlHandler-ISAPI-4.0_64bit>
< remove name =ExtensionlessUrlHandler-Integrated-4.0>
< add name =ExtensionlessUrlHandler-ISAPI-4.0_32bitpath =*。verb =GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONSmodules =IsapiModulescriptprocessor =%windir %\ Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dllprecondition =classicMode,runtimeVersionv4.0,bitness32responsebufferlimit =0>
< add name =ExtensionlessUrlHandler-ISAPI-4.0_64bitpath =*。verb =GET,HEAD,POST,DEBUG,P UT,DELETE,PATCH,OPTIONSmodules =IsapiModulescriptprocessor =%windir%\ Microsoft.NET\Framework64 \v4.0.30319 \ aspnet_isapi.dllprecondition =classicMode,runtimeVersionv4.0,bitness64responsebufferlimit =0>
< add name =ExtensionlessUrlHandler-Integrated-4.0path =*。verb =GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS type =System.Web.Handlers.TransferRequestHandlerprecondition =integratedMode,runtimeVersionv4.0>
< runtime> ;
< assemblybinding xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentassembly>
< ; assemblyidentity name =System.Web.Helperspublickeytoken =31bf3856ad364e35>
< bindingredirect oldversion =1.0.0.0-2.0.0.0newversion =2.0.0.0> < br $>
< dependentassembly>
< assemblyidentity name =System.Web.Mvcpublickeytoken =31bf3856ad364e35>
< bindingredirect oldversion =0.0.0.0-4 .0.0.0newversion =4.0.0.0>
< dependentassembly>
< assemblyidentity name =WebGrease publickeytoken =31bf3856ad364e35>
< bindingredirect oldversion =0.0.0.0-1.6.5135.21930newversion =1.6.5135.21930>
< entityframework>
< defaultconnectionfactory type =System.Data.Entity.Infrastructure.LocalDbConnectionFactory,EntityFramework >
< parameters>
< parameter value =v11.0>
这意味着,此变量在当前不存在给定的背景。可以使用if ... else块,try ... catch块或函数等创建上下文。如果无法映射变量,C#编译器将引发此错误。 提示:您是否误解了变量名称,C#区分大小写。
您应该在MSDN上阅读更多相关内容:编译器错误CS0103 [ ^ ]
That means, this variable does not exist in the current given context. The context can be created using if...else block, try...catch block or in a function etc. If a variable cannot be mapped to, C# compiler will raise this error. Hint: Are you misnaming the variable name, C# is case sensitive.
You should read more about it on MSDN: Compiler Error CS0103[^]
这篇关于CS0103:当前上下文MVC 4.0中不存在名称“url”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!