[训练]ASP.NET MVC 5 – 程式范例-留言板1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication1.Models;
using WebApplication1.Services;

namespace WebApplication1.Controllers
{
    public class MessageController : Controller
    {
        messageDBService data = new messageDBService(); //實作Services的物件 (其含有兩個方法:1.取得資料庫資料並回傳 2.接收資料並寫進資料庫)
        // GET: Message
        public ActionResult Index()             //執行Index檢視頁面 (首頁或索引頁面)
        {
            return View(data.GetData());        //將資料傳回View (使用方法1.)
        }

        public ActionResult Create()            //執行Create檢視頁面 (新增資料的頁面)
        {
            return View();
        }

        [HttpPost]                              //當瀏覽器發送HTTP POST請求才會執行
        public ActionResult Create(string Article_title, string Content)        //當使用Create這個Action且有帶參數時
        {
            data.DBCreate(Article_title, Content);      //把資料寫進資料庫 (使用方法2.)

            return RedirectToAction("Index");           //回到Index這個Action
        }
    }
}

2 則留言

  1. 匿名 says:

    '10101

发表回覆 匿名 取消回复

您的电子邮件地址不会被公开. 必需的地方已做标记 *

本网站使用的Akismet,以减少垃圾邮件. 了解您的意见如何处理数据.