Generating two Checkbox tags being a Hidden in Aspnet MVC

Asked

Viewed 45 times

1

Goodnight

@Html.CheckBox("Agree", new { value = false, @class = "filled-in", @id = "filled-in-box" })

When I Checkbox in Aspnet, by the above command, it is generating me two Tags being that one is Hidden, as I am using the materialize css, it is getting buggy, playing the Checkbox left to -9999, if I remove the Hidden node the layout is correct, it is possible that it does not generate this Hidden Input Tag?

 <input class="filled-in" id="filled-in-box" name="Agree" value="False" type="checkbox">
 <input name="Agree" value="false" type="hidden">

So far, the option I had was to create an extension method that removes the Hidden tag

public static MvcHtmlString RemoveHiddenTag(this MvcHtmlString pValue) 
{ 
    const string pattern = @"<input name=""[^""]+"" type=""hidden"" value=""false"" />"; 
    string result = Regex.Replace(pValue.ToString(), pattern, ""); 
    return MvcHtmlString.Create(result); 
} 
  • You can put in your question the distorted screen !!!??? and how should it look! Maybe the problem is in css? this generation of tags is just like that!!

  • 1

    @Virgilionovic I’ve been searching a lot on forums and I saw that it is not a bug, so I understood in Aspnet MVC it generates the Hidden Tag along with the Checkbox in case Flag is not marked it sends the false to the Model (Although Remove Hidden and do not have this problem)as the project uses Materialize CSS, a custom Checkbox and he who was getting bugged when he had the Hidden Tag picked up the Left from the Checkbox for -9999, so I didn’t have to keep writing additional CSS using the function I wrote (Updated in Post) to remove the Hidden Tag.

  • Yes, I even know that Asp.net MVC does this, and I found it strange, already use materialize and I have no problems!

  • @Virgilionovic to start with the Web part now, I always worked on the Back-End part, maybe something else in CSS may be influencing, but as I didn’t have much time to look for solution or perform tests I chose to remove Hidden.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.