Part 50 - Detect errors in views at compile time
来源:互联网 发布:竹书纪年 知乎 编辑:程序博客网 时间:2024/05/19 08:37
In this section, we will discuss, detecting errors in views at compile-time rather than at run-time.
The following code will display employee's FullName and Gender. Here we are working with a strongly typed view. Employee is the model class for this view. This class has got"FullName" and "Gender" properties.
@model MVCDemo.Models.Employee
<fieldset>
<legend>Employee</legend>
<div class="display-label">
@Html.DisplayNameFor(model => model.FullName)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.FullName)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Gender)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Gender)
</div>
</fieldset>
For example, if you mis-spell FullName property as shown below, and when you compile the project, you wouldn't get any compile time errors.
@Html.DisplayNameFor(model => model.FullName1)
You will only come to know, about the error when the page crashes at run-time. If you want to enable compile time error checking for views in MVC
1. Open MVC project file using a notepad. Project files have the extension of .csproj or.vbproj
2. Search for MvcBuildViews under PropertyGroup. MvcBuildViews is false by default. Turn this to true as shown below.
<MvcBuildViews>true</MvcBuildViews>
3. Save the changes.
If you now build the project, you should get compile time error.
Please Note: Pre-compiling views is different from compile-time error checking. We will discuss pre-compiling views in a later video session.
- Part 50 - Detect errors in views at compile time
- The operation overflows at compile time in checked mode
- Memory Ordering at Compile Time
- Memory Ordering at Compile Time
- Memory Ordering at Compile Time
- Catching errors early with compile-time assertions
- [pig] encountered errors at the first time
- Part 52 - Partial views in mvc
- Item 28. Minimizing Compile-time Dependencies part 3
- Item 27. Minimizing Compile-time Dependencies part 2
- Item 26. Minimizing Compile-time Dependencies part 1
- Item 26. Minimizing Compile-time Dependencies part 1
- Nonvirtual Calls Are Resolved at Compile Time【c++ primer】
- Troubleshooting in Office at Run Time
- WRF compile errors
- Compile- vs load-time weaving performance in Spring
- Likes Dislike Improving Performance in C++ with Compile Time Polymorphism
- Why this code compile OK, but throw ClassCastException at run time?
- SVN 创建分支
- 08练习
- HTML第八章上机练习1
- RabbitMQ高可用性集群镜像实施方案
- 21. Merge Two Sorted Lists
- Part 50 - Detect errors in views at compile time
- easyUI表单
- list交集,Array相等
- Opencv中提取图像中的轮廓及中心点
- solr学习(一、solr最新6.2.0版本安装配置图文教程 )
- Sublime Text3 作Markdown编辑器 配置
- 搭建Git服务器
- 使用 System.Convert 轉換資料型別+C#判断数据类型
- Docker第一个例子