milandjukic88
milandjukic88

Reputation: 1115

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

Scenario:

This is bizarre for me right now.. When I submit form to controller all input fields are mapped correctly, but this:

<input asp-for="Id" disabled class="form-control" value="something"/>

wont (always null).

The problem is:

when i remove disabled works perfectly!

I have another page with similar disabled input field and that page works fine. What happening here?

Upvotes: 1

Views: 4704

Answers (3)

next_rock_
next_rock_

Reputation: 1

If your Input Field values coming from another page or database use "readonly".

Upvotes: 0

Xueli Chen
Xueli Chen

Reputation: 12695

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

Upvotes: 10

LevaniK
LevaniK

Reputation: 26

Are you trying to pass a default value if disabled? I'm not sure what are you trying to pass but try specifying the value attribute in your input, like:

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

Upvotes: 0

Related Questions