我有一个可以在本地完美工作的剃须刀2.0格式。我已经验证过,针对MVC,Razor和helpers的dll都是最新版本。我在每个使用@Html.BeginForm
的页面上都有这个例外,并且参数不一样。 MVC的网页似乎工作正常,只要没有形成佣工使用:MVC 4.0字符串未被识别为有效的布尔值
Exception:
[FormatException: String was not recognized as a valid Boolean.]
System.Boolean.Parse(String value) +13981920
System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider
provider) +811
System.Web.Mvc.ViewContext.ScopeGet(IDictionary`2 scope, String name, TValue
defaultValue) +89
System.Web.Mvc.ScopeCache..ctor(IDictionary`2 scope) +75
System.Web.Mvc.ScopeCache.Get(IDictionary`2 scope, HttpContextBase httpContext) +299
System.Web.Mvc.ViewContext.GetClientValidationEnabled(IDictionary`2 scope,
HttpContextBase
httpContext) +9
System.Web.Mvc.Html.FormExtensions.FormHelper(HtmlHelper htmlHelper, String formAction,
`enter code here`FormMethod method, IDictionary`2 htmlAttributes) +233
System.Web.Mvc.Html.FormExtensions.BeginForm(HtmlHelper htmlHelper, String actionName,
String controllerName, FormMethod method, Object htmlAttributes) +134
ASP._Page_Views_Portal_LoginForm_cshtml.Execute() in
e:\WebRoot\NW_QA_BleedHR\Views\Portal\LoginForm.cshtml:4
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,
TextWriter writer, WebPageRenderingBase startPage) +196
System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String
partialViewName, Object model, ViewDataDictionary viewData) +147
ASP._Page_Views_Portal_Welcome_cshtml.Execute() in
e:\WebRoot\NW_QA_BleedHR\Views\Portal\Welcome.cshtml:9
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
System.Web.WebPages.StartPage.ExecutePageHierarchy() +143
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,
TextWriter writer, WebPageRenderingBase startPage) +181
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
+380
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()
+33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter,
ResultExecutingContext preContext, Func`1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext
controllerContext, IList`1 filters, ActionResult actionResult) +263
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult
asyncResult) +240
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +288
这种形式是死的简单:
@model GIS.Pangea.NW.Presentation.ViewModels.LoginView
<div id="DOAlogin_div">
@using (Html.BeginForm("CandidateLogin", "account", FormMethod.Post, new { id = "loginform" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary()
<table id="loginForm_tb">
<tr>
<td colspan="2" id="loginHeader_td">
<h3 id="loginHeader_h3">@Model.ReturningApplicantText</h3>
</td>
</tr>
<tr>
<td class="fieldName_td" id="username_td">
@Html.LabelFor(p=>Model.LoginDto.UserName)
</td>
<td class="fieldData_td" id="usernameinput_td">
@Html.TextBoxFor(p => Model.LoginDto.UserName, new {id="UserName",Name="UserName" })
@Html.ValidationMessage("UserName")
</td>
</tr>
<tr>
<td class="fieldName_td" id="password_td">
<label for="Password">
@Html.Encode(Model.PasswordText)
</label>
</td>
<td class="fieldData_td" id="passwordinput_td">
@Html.PasswordFor(p=>Model.LoginDto.Password, new {id="Password",Name="Password" })
@Html.ValidationMessage("Password")
</td>
</tr>
<tr>
<td colspan="2" id="forgotPassword_td">
@Html.ActionLink("Forgot Username or Password?","ForgotPassword")
</td>
</tr>
<tr>
<td colspan="2" id="loginSubmit_td" class="submit_td">
<input type="submit" class="formButton" value="@Model.LoginButtonText" />
</td>
</tr>
<tr>
<td colspan="2" id="loginValidation_td">
@if (!String.IsNullOrEmpty(Model.LoginDto.ValidationMessage))
{
<span class="validationMessage">@Model.LoginDto.ValidationMessage</span>
}
</td>
</tr>
</table>
}
</div>
我最初怀疑DLL的错误或丢失的版本。所有MVC组件应该在bin文件夹,我已经验证了这一点(至少在顶层的dll)
Here is my view config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<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.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="MVCControlsToolkit.Core" />
<add namespace="MVCControlsToolkit.Controls" />
<add namespace="MVCControlsToolkit.Controls.Validation" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.5">
<assemblies>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler" />
</httpHandlers>
<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=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
This project uses a combination of ASP pages and MVC Views, and previously was working with webforms 1.0 and MVC 2.0. The application is setup as an application under the default website. I've seen lots of variations with this same exception but most came down to syntax errors in the form helpers. This seems to be more environmentally related. Any help would be greatly appreciated!
请你可以从你的.cshtml文件中发布一个代码样本导致错误?在剃刀视图中使用表单的推荐方法是使用一个使用语句,即@using(Html.BeginForm()){}不知道这是否有助于... – 2013-05-14 18:27:35
嗨,解决您的问题的任何运气?有同样的问题,但无法找到解决方案。 – Alyek 2013-06-05 07:21:31