@using(Html.BeginForm()) returning Format exception in mvc4 on IIS 7.5 RRS feed

  • Question

  • User1081739577 posted

    I have an MVC4 web app running without any issues on my dev machine but once i deploy it to the host server i get the following exception thrown on `@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: <section>
    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.<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) +230
    System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +20
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +20
    System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>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


    @model FamilyBook.Models.Account.LoginUserModel
    @using(Html.BeginForm(new { returnurl = ViewBag.Returnurl }))
    <legend>Login with local account</legend>
    <div class="editor-label">
    @Html.LabelFor(model => model.Username)
    <div class="editor-field">
    @Html.EditorFor(model => model.Username)
    @Html.ValidationMessageFor(model => model.Username)
    <div class="editor-label">
    @Html.LabelFor(model => model.Password)
    <div class="editor-field">
    @Html.PasswordFor(model => model.Password)
    @Html.ValidationMessageFor(model => model.Password)
    <div class="editor-label">
    @Html.LabelFor(model => model.RememberMe)
    <div class="editor-field">
    @Html.CheckBoxFor(model => model.RememberMe)
    <input type="submit" value="Login" />

    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.

    Recently when checking if the problem is only in the login view showed that any view that is using razor sytanx is returning the same error message above.

    I have been struggling with this for while now and if any one could shade some ligth on the problem i a would be very grateful.

    Thank you.

    Tuesday, April 16, 2013 5:02 PM


All replies

  • User281315223 posted

    It looks like possibly one of your properties is attempting to parse a string value as a boolean and it is throwing this exception. The only property that looks like it could possibly do that would be the RememberMe property (as it should be typically expecting a bool).

    Have you tried changing the parameters that you are passing into your Form? As you are using the anonymous htmlAttributes object, which requires two additional parameters (Action and Controller) before it : 

    @using(Html.BeginForm("Action", "Controller", new { returnurl = ViewBag.Returnurl }))
         <!-- Form Contents -->

    Have you made any changes to the AccountModel that is used to populate this form?

    Tuesday, April 16, 2013 5:13 PM
  • User1081739577 posted

    I came to the same conclussion that the RememberMe property was the cause of the error and commented it out to see if it resolved the problem, but it didn't. I also tried your solution about adding action and controller name to the Html.BeginForm and got no change.

    I have also tried to manulay copy over the Razor dlls to the host in the bin directory for the site to see if this also was the casue but didn't change any thing.

    Tuesday, April 16, 2013 5:39 PM
  • User-166373564 posted

    Hi Alyek

    exception thrown on `@using(Html.BeginForm())`.

    String was not recognized as a valid Boolean.

    According to the error message,  this is not a web application deployment issue, it seems that you don't use @using(Html.BeginForm()) properly, I think you could get help from our MVC forum for this Html.BeginForm issue, it can get more quick and positive response there,

    MVC forum(http://forums.asp.net/1146.aspx/1?MVC)

    hope it helps you,

    With regards

    Tuesday, April 23, 2013 3:29 AM
  • User1081739577 posted


    Sorry for the delay.

    This issue has to do with deployment due to that the mvc application works fine without any problems on my dev machinen and this only occurs when its deployed to the hosting server. 

    At the moment i have tried a lot of different approches to solve the problem but without any success on solving this problem. It seems that every page/view that has a @using(Html.BeginForm()){} does cause the problem.

    With regards

    Friday, July 19, 2013 3:56 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 29, 2013 2:08 PM