Data inserting null for disabled form fields razor pages

Blooming Developer 281 Reputation points
2021-11-30T09:48:12.3+00:00

Hi All,

I have a form with fields which are accesssible for certain userroles.
For example if UserRole A login , the y can view the entire form field but certain fields will be restricted to edit.
To acheive this i made those fields disbaled. Now when im login as UserRole B and submitting the form,the values of the disabled field is updated as null.
Do i need to set hidden fields for each userroles?

Any help would be appreciated.Thanks.

Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-12-01T03:14:43.047+00:00

    According to your description, I suggest you could directly use readonly instead of disable to achieve your requirement .

    Details, you could refer to below codes:

    <form asp-action="TestPost">  
        <input name="name" value="test" readonly="readonly" />  
      
        <input  type="submit" value="Click"/>  
    </form>  
    

    Result:

    153931-image.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.