0

I create a controller for Category table and have generated CRUD metods.

enter image description here

In the CREATE action method, how can I make the CategoryID input disappear, and after entering CategoryName, the CategoryID column will automatically increment when adding a new entry to the table.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Abapito
  • 73
  • 7
  • 2
    Don't do this in the frontend - let the backend database handle this, it's better at stuff like that! If you're using SQL Server - use an `INT IDENTITY` column for your `ID` where SQL Server handles dishing out the unique values – marc_s Sep 04 '22 at 15:21
  • Where used INT IDENTITY in Visual or SQL SERVER MANAGEMENT STUDIO? – Abapito Sep 05 '22 at 18:11
  • You can use both tools - but the `INT IDENTITY` is a **database definition / constraint** - so you need to do this in the database table - not your code. – marc_s Sep 05 '22 at 19:42

1 Answers1

0

You can just remove the controls (textbox and label) from your create view.

Additionally, you can remove it from the list of parameters the POST method is expecting example

Change this:

public ActionResult Create([Bind(Include = "CategoryID,CategoryName")] Category category)

to:

public ActionResult Create([Bind(Include = "CategoryName")] Category category)
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dolian
  • 12
  • 2