Asp.Net之MVC(四)

Razior视图模型

1.文件新建

Asp.Net之MVC(四)

Asp.Net之MVC(四)

此文件与Shared文件夹下的_Layout.cshtml有关。

Asp.Net之MVC(四)

Asp.Net之MVC(四)

其中@RenderBody()内容为Index页面的输出内容。

Asp.Net之MVC(四)

如果在Layout.cshtml文件中添加了@RenderSection("head");   @RenderSection("foot");等内容。在在Index.cshtml文件页要写入相应的内容。否则报错!!!!

Asp.Net之MVC(四)

2.引用与导入

 

Asp.Net之MVC(四)

Asp.Net之MVC(四)

Asp.Net之MVC(四)

可以直接使用,非常方便。

3.小练习

Asp.Net之MVC(四)

Asp.Net之MVC(四)

可以使用@符号直接输出结果。

Asp.Net之MVC(四)

 

Asp.Net之MVC(四)

可以直接渲染样式输出。

Asp.Net之MVC(四)

Asp.Net之MVC(四)

并没有渲染。查看网页元素,

Asp.Net之MVC(四)

编码发生变化。改写:

Asp.Net之MVC(四)

Asp.Net之MVC(四)

进行了渲染,再次查看网页源代码:

Asp.Net之MVC(四)