ASP. net mvc + LINQ develop a book sales site (10): managed by the author

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.