locked
Disabled input submission problem in ASP.NET MVC RRS feed

  • Question

  • User-2059141420 posted

    Hi guys,
    In my MVC view I have made some input disabled. But those values are required in model. So, I need to submit in controller post method. How can I submit those? Thanks for your help!

    Sunday, January 13, 2019 4:25 AM

Answers

  • User-552477072 posted

    Hi Robert,

    Basicall, I use this way for CheckBox or CheckBoxFor because making it disabled is causing the losing the value. Readonly doesn't work on checkbox neither.

    @Html.DisplayFor(m => m.column1)
    @Html.HiddenFor(m => m.column1)

    You also can try 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 13, 2019 4:36 AM
  • User-552477072 posted

    You can also use code like this before the form submits:
    $(":disabled", $('#frmMain')).removeAttr("disabled");

    For more to know you can follow this 

    http://davecallan.com/posting-disabled-checkboxes-mvc-razor-views/#comment-11033

    Please mark as answer if it helps you. Thanks!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 13, 2019 4:49 AM

All replies

  • User-552477072 posted

    Hi Robert,

    Basicall, I use this way for CheckBox or CheckBoxFor because making it disabled is causing the losing the value. Readonly doesn't work on checkbox neither.

    @Html.DisplayFor(m => m.column1)
    @Html.HiddenFor(m => m.column1)

    You also can try 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 13, 2019 4:36 AM
  • User-2059141420 posted

    Hi

    it looks fine. But I want to avoid hidden

    Sunday, January 13, 2019 4:45 AM
  • User-552477072 posted

    You can also use code like this before the form submits:
    $(":disabled", $('#frmMain')).removeAttr("disabled");

    For more to know you can follow this 

    http://davecallan.com/posting-disabled-checkboxes-mvc-razor-views/#comment-11033

    Please mark as answer if it helps you. Thanks!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 13, 2019 4:49 AM