The author adds, deletes, and modifies directories, which are similar to the preceding Directory management. Here we use more mvc html helper.
1. Previously we put all the data access into the bookshopdbdatacontext sub-class, but if there are many functions, it is messy. Here we put each function in a file.
First, we create a dalbase abstract class in the model. Of course, you can also create a dal layer.
2.Let's create another authordal with the following content:
Q: I think it's weird to see the yellow part above, because I got the model from the database, but if this is a new author, in addition, the authorid is already available in the database. I mean to modify the database directly based on the new author. I don't know how to do this. Can anyone familiar with LINQ tell me?
3.Browse author
(1) Create an authorcontroller under the Controller
(2) create an author directory under the view and create an allauthors. aspx directory under the author directory.
Modify allauthors. aspx. CS as follows:
(3) Modify allauthors. aspx as follows,
NOTE: For the two highlighted yellow scenes above, we use authorid instead of ID. If we want to edit the address, such as Edit/1 or edit/2, the default route must be modified to enable global. asax, add the following yellowCode
(4) because there is no data, we can see the following results:
4. Add Author:
(1) Modify authorcontroller and add the following method:
(2) We also need to create an addauthor. aspx file in the view \ author directory.
Modify addauthor. aspx as follows: (yellow shows some mvc html helper usage)
5. Author:
(1) Add the following method to authorcontroller
(2) Add editauthor. aspx under view \ author
Modify editauthor. aspx. CS as follows:
Modify editauthor. aspx as follows:
Q: I can't go to the editsaved action by using the above red (commented out) method. I don't know why, and I reported an error, saying it's beyond the boundary. Which brother knows why? Thank you!
6. Delete the author
It is easy to delete. Add the following method to authorcontroller:
Note: verification is not added here. You can refer to the above blog method to add verification.