New MVC World

Note:


/Controllers:controllers respond to input from the browser,decide what to do with it,and return response to user .

/Views:views hold our UI templates.

/Models:models hold and manipulate data.

/Content:This folder holds our images,CSS,and any other static content.

/Scripts :this folder holds our Javascript files.


利用方法HttpUtility.HtmlEncode 来预处理用户输入。来阻止用户用链接向视图中注入Javascript代码或Html标记。


 当控制器没有指定视图的名称时,操作方法就会返回约定的视图(即在ControllerName 目录,不带Controller后缀)下查找与action名称同名的视图。如果重写则可以提供视图名称以渲染。EG.

1 Pulic ActionResult Index(){
2     ViewBay.Message="字符串";
3     return View("NotIndex");
4 }

 如果想完全定位视图则可以使用~符号。(必须提供扩展名.cshtml)

1  Pulic ActionResult Index(){
2      ViewBay.Message="字符串";
3      return View("~/Views/Example/Index.cshtml");
4  }

 ViewData和ViewBag

数据从控制器传送到视图是通过一个名为ViewData的ViewDataDictionay。

可以通过以下方式来设置值:

以前常用:

ViewData["CurrentTime"]=DataTime.Now;

  ASP.NET MVC3拥有更简单的方法:

ViewBag.CurrentTime=DataTime.Now;  


如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨小小打赏一下吧,如果囊中羞涩,不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!

本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.
qq群 微信
原文地址:https://www.cnblogs.com/hoaprox/p/3556058.html