"1"
The Model adds a UserInfo class UserInfo.cs
Using system;using system.collections.generic;using system.linq;using system.web;namespace MvcApplication1.Models{ Public class UserInfo {public string Name {get; set;} public int Age {get; set;} public string Gender {get;set;}} }
Controller HomeController.cs
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using Mvcapplication1.models;namespace mvcapplication1.controllers{public class Homecontroller:controller { //// GET:/home/public actionresult Index () { return View (); } Public ActionResult UserInfo () { list<userinfo> UserInfo = new List<userinfo> () { New UserInfo () {name= "Small w King", Age=18, gender= "female"}, new UserInfo () {Name = "Xiao Li", age = +, Gender = "Male"} }; viewdata["userinfo"] = userinfo; return View ();}} }
Views: userinfo.aspx
<%@ page language= "C #" inherits= "system.web.mvc.viewpage<dynamic>"%> <!--here is the Mvcapplication1.models namespace--><%@ import namespace= "Mvcapplication1.models" where the UserInfo class is introduced%> <! DOCTYPE html>
MVC General Data presentation and, strongly typed data display