A. Create an MVC project of the basic type.
B.model directory, create the file:
LoginModel.cs:
Using system;using system.collections.generic;using system.linq;using system.web;namespace mvcpartialviewtest.models{public class Loginmodel {public string Name { get { return} "Zhang San"; } } public string Remark { get { return ' flight student. '; } } Public double score { get { return 99.12; } }}
C. Create a HomeController.cs file:
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using Mvcpartialviewtest.models;namespace mvcpartialviewtest.controllers{public class Homecontroller:controller { //// GET:/home/public actionresult Index () { Viewdata.model = new Loginmodel (); return View (); } Public ActionResult Getpartialview () { return Partialview ("Partiallink"); } }
C. Create the appropriate Partialview:
1) PartialLink.cs:
<a href= "http://www.sina.com.cn" > Sina </a> <a href= "http://www.sohu.com" > Sohu </a> <a href= " http://www.exesoft.cn "> Easy software </a>
2) Partialdatafromloginmodel.cshtml:
@using Mvcpartialviewtest.models@model loginmodel
3) Partialdatafromview.cshtml:
@model system.double
D. Create the View file:
Index.cshtml:
@using Mvcpartialviewtest.models@model loginmodel@{ viewbag.title = "Index";}
E.:
AspNet MVC4 teaching -22:asp.net MVC4 Partial View Technology Quick Application Demo