我是ASP.NET MVC的新手,我想制作强类型视图。不知怎的,Razor引擎无法识别@using
标记,并且会在运行时给出解析器错误:
Unexpected "using" keyword after "@" character.
Once inside code, you do not need to prefix constructs like "using" with "@".
这就是我所拥有的:
@{
@using MyNamespace.ViewModels // Parser error shows this line.
@model EmployeeViewModel // MyNamespace.ViewModels.EmployeeViewModel alone works.
}
(omitted code)
Employee Name : @Model.EmployeeName <br />
答案 0 :(得分:3)
模型声明需要先于任何其他代码。接下来,您只需单独使用using语句即可。
@model EmployeeViewModel
@using MyNamespace.ViewModels
(omitted code)
Employee Name : @Model.EmployeeName <br />