[training]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. 匿名訪客表示:

    ‘10101

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料