0

View Code:

@Html.DropDownListFor(m => m.mode, new List<SelectListItem>
                                   {
                                   {
                                      new SelectListItem{ Text="Select", Value = "10000" },
                                      new SelectListItem{ Text="Add", Value = "10001" },
                                      new SelectListItem{ Text="Modify", Value="10002" }
}, htmlAttributes: new { @class = "form-control", @id = "cboFunctions", @onChange = "FunctionChange();" })

after disabled by java-scrip code its not passing value from view to controller.

$("#cboFunctions").prop("disabled", true);

i'm also try store value in hidden field but not passing value

any help would be appreciated Thanks.

Prabhat Sinha
  • 1,500
  • 20
  • 32
  • I suspect you can solve your problem by using [readonly instead of disabled](https://stackoverflow.com/a/7730719/728795) – Andrei Sep 11 '18 at 10:11
  • No read only not solution i want after disabled would not be select any other value – Prabhat Sinha Sep 11 '18 at 10:12
  • 1
    You cannot. Disabled controls do not submit a value (and there is no such thing as a readonly ` –  Sep 11 '18 at 10:13

1 Answers1

1

While unclear why the dropdown is being disabled, it has already been mentioned that disabled inputs do not send data.

You would need to add a hidden input for that property for it to be forwarded on to the server when the form is posted.

 @Html.HiddenFor(m => m.mode)

So as you are using java script you can set the hidden input with the locked in value so that it get posted.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
  • Hi, nkosi actually my application require its first select option like add, modify....delete then fill the control value and submit but within filling process avoid to change dropdown list box its really needed. i tried hidden field but its not passing the value. – Prabhat Sinha Sep 11 '18 at 10:32