asp.net-mvc-4 - @using(Html.BeginForm()) 返回格式异常 mvc4

标签 asp.net-mvc-4 web-config iis-7.5

我有一个 MVC4 Web 应用程序在我的开发计算机上运行,​​没有任何问题,但是一旦我将其部署到主机服务器,我就会在 @using(Html.BeginForm()) 上抛出以下异常。


        String was not recognized as a valid Boolean.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.FormatException: String was not recognized as a valid Boolean.

    Source Error: 


    Line 4:  
    Line 5:  
    Line 6:      @using(Html.BeginForm(new { returnurl = ViewBag.Returnurl }))
    Line 7:      {
    Line 8:          @Html.AntiForgeryToken()

    Source File: e:\Sites\familybook\Views\Login\Login.cshtml    Line: 6 

    Stack Trace: 


    [FormatException: String was not recognized as a valid Boolean.]
       System.Boolean.Parse(String value) +12636900
       System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +12819466
       System.Web.Mvc.ViewContext.ScopeGet(IDictionary`2 scope, String name, TValue defaultValue) +89
       System.Web.Mvc.ScopeCache..ctor(IDictionary`2 scope) +48
       System.Web.Mvc.ScopeCache.Get(IDictionary`2 scope, HttpContextBase httpContext) +282
       System.Web.Mvc.ViewContext.GetClientValidationEnabled(IDictionary`2 scope, HttpContextBase httpContext) +9
       System.Web.Mvc.Html.FormExtensions.FormHelper(HtmlHelper htmlHelper, String formAction, FormMethod method, IDictionary`2 htmlAttributes) +162
       System.Web.Mvc.Html.FormExtensions.BeginForm(HtmlHelper htmlHelper, Object routeValues) +192
       ASP._Page_Views_Login_Login_cshtml.Execute() in e:\Sites\familybook\Views\Login\Login.cshtml:6
       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.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.b__22(IAsyncResult asyncResult) +230
       System.Web.Mvc.c__DisplayClass1d.b__18(IAsyncResult asyncResult) +28
       System.Web.Mvc.Async.c__DisplayClass4.b__3(IAsyncResult ar) +20
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
       System.Web.Mvc.Async.c__DisplayClass4.b__3(IAsyncResult ar) +20
       System.Web.Mvc.c__DisplayClass8.b__3(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.c__DisplayClass4.b__3(IAsyncResult ar) +20
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

The host server is a Windows server 2008 R2 64-bit with IIS 7.5 and the latest updates for OS and .NET 4 framework installed on it.

The funny thing is that when I deployed before I did not get this error until I updated the server with windows updates. Another thing that I have noted is that if I set the type of publish to debug the application works without any problems while it does not with release publish type.

I did also try to deploy to local folder on my dev machine and then copy the content to the host server, but got the same end results.

Edit:

 @model FamilyBook.Models.Account.LoginUserModel

@Scripts.Render("~/bundles/jqueryval")

<section>
    @using(Html.BeginForm(new { returnurl = ViewBag.Returnurl }))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

        <fieldset>
            <legend>Login with local account</legend>

            <div class="editor-label">
                @Html.LabelFor(model => model.Username)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Username)
                @Html.ValidationMessageFor(model => model.Username)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(model => model.Password)
                @Html.ValidationMessageFor(model => model.Password)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.RememberMe)
            </div>
            <div class="editor-field">
                @Html.CheckBoxFor(model => model.RememberMe)
            </div>

            <p>
                <input type="submit" value="Login" />
            </p>

        </fieldset>
    }
</section>

最佳答案

问题的根本原因是,当对自定义键的 appSettings 执行 web.conf 转换时,它们覆盖了与第一个自定义键具有相同值的所有其他键。所以对 -> 进行简单的更改就解决了问题。 这可以在堆栈跟踪中看到,当调用 MVC System.Web.Mvc.ViewContext.GetClientValidationEnabled 中的此函数来检查 clientSideValidation 是否启用时,应用程序崩溃。更多信息可以在这个线程http://forums.asp.net/t/1924833.aspx/1?Format+exception+on+Html+BeginForm+String+was+not+recognized+as+a+valid+boolean中找到

关于asp.net-mvc-4 - @using(Html.BeginForm()) 返回格式异常 mvc4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15982049/

相关文章:

.net - 重复 'system.web.extensions/scripting/scriptResourceHandler'

c# - WCF 服务在方法请求上返回 404

c# - PartialView 使用 LINQ 传递自定义列表

c# - asp.net mvc Bundle.IncludeDirectory 示例?

xslt - 通过 configSource 链接到 web.config 的部分配置文件可以在 web 项目中转换吗?

asp.net - web.config 下用于 url 重写的多个外部文件

c# - Html.BeginForm 发布模型为空

javascript - AngularJS 发布到 Controller 并重定向到另一个页面

.net - .NET 中编译器选项的相对路径

asp.net - 在 IIS 7.5 下调试时生成的程序集与源不匹配的问题