一、使用View Data首先要在Controller里加代码:public class ProductController : Controller{//// GET: /Product/public ActionResult Index(){ViewData["Messag......
protected virtual string GetMatch(Match m, ViewDataDictionary viewData)
{
if (m.Success)
{
string key = m.Result("$1");
if (viewData.ContainsKey(key))
{
return viewData[key].ToString();
}
}
return string.Empty;
}
}
}
定义一个Controller:
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class SimpleController : Controller
{
public ActionResult Index()
{
ViewData["message"] = "Hello World!";
return View();
}
}
}
而页面可以写成:Views\Simple\Index.simple
<html>
<head><title>Index Simple View</title></head>
<body>
<h1>{message}</h1>
</body>
</html>
主要看{message}被解析出来了
4/4 首页 上一页 2 3 4 |