ASP.NET MVC -1控制器**向**视图**传递数据的方式:

MVC,控制器视图传递数据的方式:

  1. ViewData[“key”] = value, value可以为任意类型的数据

control

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UI.Models;
namespace UI.Controllers
{
   
    public class StudentController : Controller
    {
   
        //
        // GET: /Student/

        public ActionResult ABC()
        {
   
            string msg = "这是控制器传递给视图的数据.....";
            ViewData[ "msg" ] = msg;
            Student s1 = new Student {
    Id = 100 , Name = "东方不败" };
            ViewData[ "student" ] = s1;
            List<Student> lst = new List<Student>( ){
   
            new Student{
   Id=101,Name="张无忌"},
            new Student{
   Id=102,Name="张翠山"},
            new Student{
   Id=103,Name="张三丰"},
            new Student{
   Id=104,Name="张松溪"}
            };
            ViewData[ "list" ] = lst;
            return View();
        }


    

你可能感兴趣的:(asp.net,mvc,.net)