首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

二、GuestBook with model

2012-10-28 
2、GuestBook with modelGuestBook with modelModel:GuestBookEntry.csInheritsSystem.Web.Mvc.ViewPage

2、GuestBook with model
GuestBook with model

Model:GuestBookEntry.cs



Inherits="System.Web.Mvc.ViewPage<Mvc2.Models.GuestBookEntry>" %>
非常重要

View : ThankYou.aspx


Controller:GuestBookController.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using Mvc2.Models;namespace Mvc2.Controllers{    public class GuestBookController : Controller    {        //        // GET: /GuestBook/        public ActionResult Index()        {            var model = new GuestBookEntry();            return View(model);        }        [HttpPost]        public ActionResult Index(GuestBookEntry entry)        {            TempData["entry"] = entry;            return RedirectToAction("ThankYou");        }        public ActionResult ThankYou()        {            if (TempData["entry"] == null)            {                return RedirectToAction("index");            }            var model = (GuestBookEntry)TempData["entry"];            return View(model);        }    }}



2011-5-16 11:50 danny

热点排行