[훈련]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. Anonymous says:

    10101 년

회신을 남겨주세요 린 Zhengen 답장 취소

귀하의 이메일 주소는 공개되지 않습니다. 필요 입력 사항은 표시되어 있습니다 *

이 사이트는 스팸을 줄이기 위해 Akismet에 사용. 귀하의 코멘트 데이터가 처리되는 방법 알아보기.