Say I have a boolean field, MyField, that I am creating a checkbox for. I would write this:
@Html.CheckBox("MyField")
. You would expect this to output a single check box but if you actually look at the HTML that is generated you will notice that is also creates a hidden field.I found out the the reason for this is written within the ASP.NET MVC source code:
if (inputType == InputType.CheckBox) { // Render an additional for checkboxes. This // addresses scenarios where unchecked checkboxes are not sent in the request. // Sending a hidden input makes it possible to know that the checkbox was present // on the page when the request was submitted. StringBuilder inputItemBuilder = new StringBuilder(); inputItemBuilder.Append(tagBuilder.ToString(TagRenderMode.SelfClosing)); TagBuilder hiddenInput = new TagBuilder("input"); hiddenInput.MergeAttribute("type", HtmlHelper.GetInputTypeString(InputType.Hidden)); hiddenInput.MergeAttribute("name", name); hiddenInput.MergeAttribute("value", "false"); inputItemBuilder.Append(hiddenInput.ToString(TagRenderMode.SelfClosing)); return inputItemBuilder.ToString(); }
I appreciate the reasoning behind this but in my scenario
MyField
is part of a ViewModel that is being sent with the form and of course boolean values are False
by default so this is wasted on my scenario.Another reason I do not like this is because I am using the GET method on my form the user will see this oddity in the querystring. Worse still, they be a developer and judge my code as rubbish not knowing it is the doing of ASP.NET MVC. I can't have that! ;)
Solution
Simple solution really. Write the HTML you want in HTML, forget about the HtmlHelper:<input type="checkbox" name="MyField" value="true" id="MyField" @Html.Raw((Model.MyField) ? "checked=\"checked\"" : "") />
Remember the
value="true"
because the default value to be sent is "on" if it is checked, which obviously can't be parsed to a Boolean.Obviously, this doesn't look that clean but I will continue to do this on forms that use the GET method.
You, sir, just helped me out of 3-hrs nightmare hunt. Thank you!
ReplyDeleteI am writing this comment with tears of joy. My marriage fell apart after 6 months because my mother In-law asked my husband to divorce me and marriage the woman she betroth to him as his wife. All this drama started happening in our marriage and my husband left me and our one month baby just so he could do as his mom wants him to.I was in tears and shattered for 6 months because I could not imagine my whole life crumbling in front of me. I could not continue with work and baby responsibilities so I quit working. Things became more difficult until my best friend advised me to meet a love doctor that fixed her marriage with a RETURN LOVER SPELL that works as fast as 12 hours after casting the spell. I concord and decided to contact this spell doctor and guess what. My husband came to my mom house with his family in less than 12 hours after casting the spell. Even his mom came back asking me for forgiveness and also to reconcile with my husband who left me. They have been coming for the past 3 days and now everyone is asking me to take him back. I am so grateful for what this love spell doctor has done for me. I am thinking of accepting his apologize and move on as family just as my mom advised.Anyone who wants their lover back should write to love doctor on Love Spell doctor on lovespelldoctor0@gmail.com God bless you as you find your happiness through this testimony.
DeleteOh yeh this work is great.
ReplyDeleteThanks, was pulling my hair out over this!
ReplyDeleteThank you! Thank you! Thank you! This was spot on and solved my problem
ReplyDeleteLove spell doctor has brought my husband back to me after 6 months of separation. My husband left me and wanted a divorce because of a young girl who is young enough to be her daughter. Your love spell has reunited my family once again after mourning and tears that I am now a single mom, but my teas has turn to Joy with your amazing return lover spell.
DeleteI am grateful for everything. Anyone experiencing heartbreak and needs their lover back should contact lovespelldoctor0@gmail.com and that will be the end of your problems in that relationship.
Love spell doctor has brought my husband back to me after 6 months of separation. My husband left me and wanted a divorce because of a young girl who is young enough to be her daughter. Your love spell has reunited my family once again after mourning and tears that I am now a single mom, but my teas has turn to Joy with your amazing return lover spell.
I am grateful for everything. Anyone experiencing heartbreak and needs their lover back should contact lovespelldoctor0@gmail.com and that will be the end of your problems in that relationship.
Love spell doctor has brought my husband back to me after 6 months of separation. My husband left me and wanted a divorce because of a young girl who is young enough to be her daughter. Your love spell has reunited my family once again after mourning and tears that I am now a single mom, but my teas has turn to Joy with your amazing return lover spell.
I am grateful for everything. Anyone experiencing heartbreak and needs their lover back should contact lovespelldoctor0@gmail.com and that will be the end of your problems in that relationship.
Many Many thanks. Now my problem is resolved.
ReplyDeleteI was wasting 2-3 hr every night since 1 week and now my issue is resolved. It's really great.
thanks so much for this!
ReplyDeleteThanks a lot
ReplyDeleteYou did really good work. I really appreciate your new and different post. Please guys keep it up and share with us some unique post in the futureMenmyshopTouch Hypersonic Double Din Player MirrorJ3L Touch Double Din PlayerHypersonic Double Din Player MirrorJ3L Double Din Player Mirror
ReplyDeleteCBSE open schoolcbse privatebanzaraonjourneyMalhotra law house
Y
Motifz Designer Lawn. 1, 2 & 3 Piece Unstitched Premium Embroidered Lawn 2019, Premium embroidered Lawn, Premium lawn, Premium lawn 2019, Motifz, Premium lawn in Pakistan. Shipping worldwide. Stitching option available.
ReplyDeleteYes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks this person tried to unlock your phone
ReplyDeleteIt should be noted that whilst ordering papers for sale at paper writing service, you can get unkind attitude. In case you feel that the bureau is trying to cheat you, don't buy term paper from it. Wordpress Tips
ReplyDeleteI have to search sites with relevant information on given topic and provide them to teacher our opinion and the article. สมัครเน็ตทรู
ReplyDeleteAcquiring Custom Assignment Writing Services from a credible firm like Legitimate Assignment Writing Company ensures that you attain excellence, especially in your College Assignment Writing Services endeavors, which can be challenging in many instances.
ReplyDeleteThat definitely possibly an amazing organize i always in truth definitely relished checking out. It's not necessarily specifically frequent i always add some choice to identify a selected matter. microsoft office 365 product key
ReplyDeleteThanks for this article very helpful. thanks. Adele net worth
ReplyDeleteGreat article Lot's of information to Read...Great Man Keep Posting and update to People..Thanks Adele net worth
ReplyDeleteSnappy disclaimer: I AM NOT BASHING ANYONE! Indeed, I was yelling that. This segment of the article is mentioning to you what I know, read, hear and involvement with gaming.
ReplyDeleteSubway surfer hack
Love spell doctor has brought my husband back to me after 6 months of separation. My husband left me and wanted a divorce because of a young girl who is young enough to be her daughter. Your love spell has reunited my family once again after mourning and tears that I am now a single mom, but my teas has turn to Joy with your amazing return lover spell.
ReplyDeleteI am grateful for everything. Anyone experiencing heartbreak and needs their lover back should contact lovespelldoctor0@gmail.com and that will be the end of your problems in that relationship.
I never believed that i will be happy again after much frustration. I have been rejected by my husband after Six(6) years of marriage just because he met another woman and he left me and the kids to suffer. One day when i was reading through the web i stumbled at a post on how chief dr lucky the great spell caster has helped people to restore broken marriages and relationships and curing of diseases. I emailed him immediately to help my situation via: chiefdrlucky@gmail.com He told me not to worry that my husband will return to me begging and shedding tears of forgiveness. I am so happy that my husband actually returned to me in 48 hours after i obeyed the words and instructions of chief dr lucky. contact him today in any of your problems for a lasting solution via: chiefdrlucky@gmail.com or call/whats app +2348132777335 Website: http://chiefdrluckysolutionhome.website2.me/
ReplyDeleteBorivali Escorts Service | Escorts Agency in Borivali | Escorts Borivali | Borivali Female Escorts | Borivali Escorts Models
ReplyDeleteBorivali Model Escorts | Cheap Borivali Escorts | Borivali Independent Escorts | Escorts Girls in Borivali | Borivali Escorts Girls
Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors. hidden marriage
ReplyDeletei will love to share my testimony to you all the people in world i got married to my husband about 2 year ago we start having problems at home like we stop sleeping on the same bed,fighting about little things he always comes home late at night,drinking too much and sleeping with other women out side i have never love any man in my life except him. he is the father of my child and i don't want to loose him because we have worked so hard together to become what we are and have today .few month ago he now decided to live me and the kid,being a single mother can be hard sometimes and so i have nobody to turn to and i was heart broken.i called my mom and explain every thing to her,my mother told me about DR.kuta how he helped her solve the problem between her and my dad i was surprise about it because they have been without each other for three and a half years and it was like a miracle how they came back to each other. i was directed to DR. kuta on his email. (drkutaherbalcenter@gmail.com) and explain everything to him,so he promise me not to worry that he will cast a spell and make things come back to how we where so much in love again and that it was another female spirit that was controlling my husband he told me that my problem will be solved within two days if i believe i said OK So he cast a spell for me and after two days my love came back asking me to forgive him i Am so happy now. so that why i decided to share my experience with every body that have such problem contact Dr kuta the great spell caster on his email addresses (drkutaherbalcenter@gmail.com)or whatsapp Dr kuta on (+2347054547814)
ReplyDeleteBuy online wholesale printed candle boxes and packaging at easy prices and shipping worldwide, with 24/7 customer support. Get a free custom quote now!!
ReplyDeleteBuy online wholesale printed custom lipstick boxes and packaging at easy prices and shipping worldwide, with 24/7 customer support. Get a free custom quote now!!
ReplyDeleteBlackbird packaging provide you with any size, shape design, custom e liquid boxes sooner than any other packaging competitor in the market
ReplyDeleteBlackbird packaging provide you with any size, shape design, cookie boxes wholesale sooner than any other packaging competitor in the market
ReplyDeletePackaging town is a one-stop solution for the short-run cbd facial oil boxes needs, and supplies. At affordable prices. Request a free quote now.
ReplyDeleteBlackbird packaging provide you with any size, shape design, custom cbd tincture boxes sooner than any other packaging competitor in the market
ReplyDeleteBlackbird packaging provide you with any size, shape design, custom cbd tincture boxes sooner than any other packaging competitor in the market
ReplyDeleteGreat Article
ReplyDeleteCloud Computing Projects
Networking Projects
Final Year
Projects for CSE
JavaScript Training in Chennai
JavaScript
Training in Chennai
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals,
Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer.
Angular Training