locked
Can't retrieve checkbox value in Controller. RRS feed

  • Question

  • User-1042970710 posted

    Dear Friends,

    I have a third party control  Shield UI Switch which is rendering html checkbox control in MVC View with CSS style,  as well all know that normally @Html.CheckBoxFor is rendered along with Hidden Text Box Control.    I bind the my model with the control and it works fine....   (In the Edit Mode).

    But when I  re-submit the changed value of the Switch control (Check Box Control in HTML)  the updated value not sending to Controller?  Anyone can help?

    @Html.ShieldSwitchFor(model => model.PublishedStatus)
    .Checked(Model.PublishedStatus)  // Set the Default Value of the Model here!
    .Cls("rounded")
    .OnText("ON")
    .OffText("OFF"))
    
    @Html.HiddenFor(model => model.PublishedStatus)
    
    

    Monday, September 16, 2019 10:47 AM

All replies

  • User475983607 posted

    The shared code shows two inputs with the same name which probably looks like an array to the model binder.   Keep in mind, the hidden field is set when the view renders.   Does the ShieldSwitchFor  documentation suggest this approach?  I don't see anything in the docs that recommends this approach.

    Have tried standard troubleshooting?  Open the browser's dev tools and verify what data is sent in the HTTP Body?  Set a break point in in your controller action and verify the action is running?  Can you explain what troubleshooting steps you have performed up to this point?  Can you share all the relevant code?

    Monday, September 16, 2019 1:00 PM