How to Submit Disabled Input in ASP.NET MVC

How do I submit disabled input in ASP.NET MVC?

Thanks to everyone:

The way i resolved this:

document.getElementById("Costo").readOnly = true;
document.getElementById("Costo").style.color = "#c0c0c0";

Note:

I got this information on the answer but i got editted.

send a jQuery disabled input value to a MVC controller

Don't use the disabled attribute use the readonly attribute instead. This will send the values to the controller.

        $("#idDireccion").attr('readonly', true);
$("#idEvento").attr('readonly', true);
$("#ddDepartamentos").attr('readonly', true);
$("#ddMunicipios").attr('readonly', true);
$("#idLugar").attr('readonly', true);
$("#datepicker").attr('readonly', true);
$("#idHoras").attr('readonly', true);
$("#idPrecio").attr('readonly', true);

How to post back disabled form control in mvc

Disabled inputs will never post back to the server. You need to use a read-only input instead.

For example:

Disabled:

@Html.TextBoxFor(model => model.Name, new { @disabled = "disabled" })

Read-only:

@Html.TextBoxFor(model => model.Name, new { @readonly = "readonly" })

When i put disabled attribute in html input tag asp.net-core mvc not mapping it

The disabled attribute for element in HTML is used to specify that the input field is disabled. A disabled input is un-clickable and unusable. It is a boolean attribute. The disabled elements are not submitted in the form.

You could use readonly instead of disabled

<input asp-for="Id" readonly class="form-control" value="[something]" />

Reference : https://stackoverflow.com/a/1355734/10201850

Values of disabled inputs will not be submitted

Yes, all browsers should not submit the disabled inputs, as they are read-only.

More information (section 17.12.1)

Attribute definitions

disabled [CI] When set for a form control, this Boolean attribute
disables the control for user input. When set, the disabled attribute
has the following effects on an element:

  • Disabled controls do not receive focus.
  • Disabled controls are skipped in tabbing navigation.
  • Disabled controls cannot be successful.

The following elements support the disabled attribute: BUTTON, INPUT,
OPTGROUP, OPTION, SELECT, and TEXTAREA.

This attribute is inherited but local declarations override the
inherited value.

How disabled elements are rendered depends on the user agent. For
example, some user agents "gray out" disabled menu items, button
labels, etc.

In this example, the INPUT element is disabled. Therefore, it cannot
receive user input nor will its value be submitted with the form.

<INPUT disabled name="fred" value="stone">

Note. The only way to modify dynamically the value of the disabled
attribute is through a script.

Disabled form inputs do not appear in the request

Elements with the disabled attribute are not submitted or you can say their values are not posted (see the second bullet point under Step 3 in the HTML 5 spec for building the form data set).

I.e.,

<input type="textbox" name="Percentage" value="100" disabled="disabled" /> 

FYI, per 17.12.1 in the HTML 4 spec:

  1. Disabled controls do not receive focus.
  2. Disabled controls are skipped in tabbing navigation.
  3. Disabled controls cannot be successfully posted.

You can use readonly attribute in your case, by doing this you will be able to post your field's data.

I.e.,

<input type="textbox" name="Percentage" value="100" readonly="readonly" />

FYI, per 17.12.2 in the HTML 4 spec:

  1. Read-only elements receive focus but cannot be modified by the user.
  2. Read-only elements are included in tabbing navigation.
  3. Read-only elements are successfully posted.

How to handle the value of the inputs with disabled html attribute in Asp.Net core Razore Pages?

Browsers does not support disabled property to submit with forms by default:

The difference between disabled and readonly is that read-only controls can still function and are still focusable, whereas disabled controls can not receive focus and are not submitted with the form and generally do not function as controls until they are enabled.

For your scenario, you can change disabled to readonly.

<input readonly asp-for="@Model.Episode.EpisodeFileName" />


Related Topics



Leave a reply



Submit