[प्रशिक्षण]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

  2. 林正恩 कहते हैं |

एक टिप्पणी छोड़ दो

कृपया ध्यान दें: टिप्पणी मॉडरेशन सक्षम है और अपनी टिप्पणी में देरी हो सकती है. कोई जरूरत नहीं अपनी टिप्पणी को पुनः सबमिट करने की आवश्यकता है.