[تدريب]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          }      }  }

اترك التعليق

يرجى ملاحظة: الاعتدال هو مكن تعليق، وربما تؤخر تعليقك. ليست هناك حاجة لإعادة تعليقك.