⺣ - רҵ·ĵϷƽ̨

ǰλãҳ > 基于MVC的个人博客系统设计与实现毕业设计 - 百度文库

基于MVC的个人博客系统设计与实现毕业设计 - 百度文库

  • 62 Ķ
  • 3
  • 2025/5/3 23:37:30

ѧԺҵƣģ

ʾ ͼ5.6 վĸҳṹͼ

ڶ ϵͳʵ

ڱϵͳǻASP.NET MVCģʽƵģÿģ鹦ܶӦMVC㣬Model, ControllerViewǰ̨ܺͺ̨ǽֱ

һǰ̨ʵ

(һ)ҳ

1View: 򿪲վҳͼ5.7ʾ

ͼ5.7 վҳ

2ControllerࣺӦControllerش£ public ViewResult index(int page) {

if (page * pageSize > BlogEntryManager.Count(0, 1)) page = page - 1; if (page <= 0) page = 1;

18

ѧԺҵƣģ

ViewData[\] = page;

List model = new List();

model = BlogEntryManager.GetList((page - 1) * pageSize, pageSize);

return View(model); } ()û

վ߿ԶԲ·Լۡ 1View: û۽ͼ5.8ʾ

ͼ5.8 û۽

2ControllerࣺӦControllerش:

public ActionResult AddComment(int page, string commentAuthor, string commentText) {

var comment = new Comment {

blog_id = page,

author = commentAuthor, body = commentText,

datecreated = DateTime.Now }; try {

if (commentAuthor.Trim().Length == 0)

ViewData.ModelState.AddModelError(commentAuthor, \);

if (commentText.Trim().Length == 0)

19

ѧԺҵƣģ

ViewData.ModelState.AddModelError(commentText, \Text not specified.\);

if (!ViewData.ModelState.IsValid)

throw new InvalidOperationException();

CommentManager.Save(comment); return RedirectToAction(\); }

catch (InvalidOperationException ex) {

return View(BlogEntryManager.GetItem(page)); } } ()ûע

δעûͨվעṦעΪվԱ 1View:ûעͼ5.9ʾ

ͼ5.9 ûע

2ControllerࣺӦControllerش£

public ActionResult Register(string userName, string email, string password, string confirmPassword)

{

ViewData[\] = MembershipService.MinPasswordLength;

if (ValidateRegistration(userName, email, password, confirmPassword)) {

MembershipCreateStatus createStatus = MembershipService.CreateUser(userName, password, email);

if (createStatus == MembershipCreateStatus.Success) {

FormsAuth.SignIn(userName, false

20

ѧԺҵƣģ

return RedirectToAction(\, \); } else {

ModelState.AddModelError(\, ErrorCodeToString(createStatus));

} }

return View(); } ()û¼

עû¼ϵͳԵ¼ͽй 1View:û¼ģͼ5.10ʾ

ͼ5.10 û¼

2ControllerࣺӦControllerش£

public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl)

{

if (!ValidateLogOn(userName, password)) {

ViewData[\] = rememberMe; return View(); }

FormsAuth.SignIn(userName, rememberMe); if (!String.IsNullOrEmpty(returnUrl)) {

return Redirect(returnUrl); } else {

return RedirectToAction(\, \); } }

21

  • ղ
  • Υٱ
  • Ȩ
ĵ10.00 Ԫ VIP
ߣ...

92ƪĵ

ĵ飺

ѧԺҵƣģ ʾ ͼ5.6 վĸҳṹͼ ڶ ϵͳʵ ڱϵͳǻASP.NET MVCģʽƵģÿģ鹦ܶӦMVC㣬Model, ControllerViewǰ̨ܺͺ̨ǽֱ һǰ̨ʵ (һ)ҳ 1View: 򿪲վҳͼ5.7ʾ ͼ5.7 վҳ 2ControllerࣺӦControllerش£ public ViewResult index(int page) { if (page * pageSize

οͿͨغɸƺŰ棩
ƪ
ʱؼۣ10 Ԫ/ ԭ:20Ԫ
VIP
ؼۣ29 Ԫ/ ԭ:99Ԫ
0.3 Ԫ/ ÿ150
ȫվɸ
VIP
ؼۣ29 Ԫ/ ԭ:99Ԫ
0.3 Ԫ/ ÿ150
ȫվɸ
עĵпܡֻĿ¼ݲȫ֮ǰעѸ޷ػ⣬ϵЭ㴦
΢ţfanwen365 QQ370150219
Copyright © ⺣ All Rights Reserved. ICP16052595-3 վͼ ͷQQ370150219 䣺370150219@qq.com