ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Create/Edit records for a grid - display Id field
Title:
B
I
{code}
?
Using the Mvc5MinSetup projet, in DinnerInput.cs, I have : public class DinnerInput { public int Id { get; set; } [Required] public string Name { get; set; } ... } I would like to have "Id" parameter in not editable when Creating/Deleting (just have it display, but not possible to set/modify the value.This is useful if the datasource is SQL and Id is auto seed by SQL). How can I do that ? Thanks Alain.
Save Changes
Cancel
Alain Rime
asked at 16 Feb 2016
use a label to display it, the rest remains the same
at 16 Feb 2016
Omu
if I use Html.LabelFor(o => o.Id), I have a problem during the Edit because the Id is 0 in the Edit function of the controller.
at 17 Feb 2016
Alain Rime
use this @(Model.Id != 0 ? Model.Id.ToString() : "")
at 17 Feb 2016
Omu
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK