I want to hide RadioButtonFor
@Html.RadioButtonFor(model => model.recommend, "RA", htmlAttributes: new { @id = "Roflag2", @onchange = "onchangetype2DL('0')" }) Call for Addln.Particulars
When i simply comment above code then my submit button is not working.
How can i do this?

Vijay Pratap SinghRank #381 · 6.6K reputationPosted Jan 3, 2024, 3:14 AM EST
If you want to hide the
RadioButtonForelement but still have it present in the HTML for the submit button to work correctly, you can use CSS to hide it. You can add a style attribute to theRadioButtonForwith thedisplay: none;property. This way, the element will be hidden, but it will still exist in the HTML, allowing your submit button to work.@Html.RadioButtonFor(model => model.recommend, "RA", htmlAttributes: new { @id = "Roflag2", @onchange = "onchangetype2DL('0')", style = "display: none;" }) Call for Addln.ParticularsThis will hide the
RadioButtonForelement on the page, but it will still be present in the HTML. If you want to hide it dynamically based on some condition, you can use a ternary operator to conditionally apply thestyleattribute:@Html.RadioButtonFor(model => model.recommend, "RA", htmlAttributes: new { @id = "Roflag2", @onchange = "onchangetype2DL('0')", style = (condition) ? "display: none;" : "" }) Call for Addln.ParticularsHope this will help
Sachin SinghRank #66 · 26.2K reputationPosted Jan 3, 2024, 3:24 AM EST
Simply commenting the radio button is not working because your controller's Action method is expecting Roflag2 value, you can set it to default 0 if you don't need it inside the model or Method parameter.
OR
you can set display none to hide the radio button
.hidden-radio { display: none; }@Html.RadioButtonFor(model => model.recommend, "RA", new { @id = "Roflag2", @onchange = "onchangetype2DL('0')", @class = "hidden-radio" })Garima BansalRank #1,555 · 1K reputationPosted Jan 3, 2024, 4:55 AM EST
@Html.RadioButtonFor(model => model.recommend, "RA", htmlAttributes: new { @id = "Roflag2", @onchange = "onchangetype2DL('0')" })Call for Addln.Particulars
i use this approach, this works fine
Thanks to Everyone
Jayraj ChhayaRank #304 · 8.2K reputationPosted Jan 3, 2024, 5:04 AM EST
To hide the RadioButtonFor in your view without affecting the functionality of the submit button, you can use CSS to hide the element. Here's how you can achieve this:
@Html.RadioButtonFor(model => model.recommend, "RA", htmlAttributes: new { @id = "Roflag2", @class = "hidden-radio" }).hidden-radio { display: none; }By setting the
displayproperty tonone, the RadioButtonFor element will be hidden from view.This approach allows you to hide the RadioButtonFor without affecting the functionality of the submit button. The submit button should continue to work as expected.
Remember to adjust the CSS class name and styling according to your specific requirements.
I hope this helps! Let me know if you have any further questions.
Allen Barber16 reputationPosted Jan 3, 2024, 9:00 AM EST
To hide the RadioButtonFor while ensuring that your submit button continues to work, you can use CSS and JavaScript/jQuery.
First, add a CSS class to the RadioButtonFor element that you want to hide.
@Html.RadioButtonFor(model => model.recommend, "RA", htmlAttributes: new { @id = "Roflag2 spacebar clicker", @class = "hidden-radio", @onchange = "onchangetype2DL('0')" })
Next, add the following CSS code to your stylesheet or within a
tag.hidden-radio {
display: none;
}
This CSS code will hide any element with the "hidden-radio" class.
To ensure that your submit button continues to work, you need to update your JavaScript/jQuery code. Make sure that the code that handles the form submission is not dependent on the hidden RadioButtonFor element.