我是MVC的新手。现在我正在学习VS2010,ASP.NET MVC 4.<% %>不能在mvc4中工作
<% %>
不适合我。我很难使用@
。
如果我用大量的if{}
编写大码,那么<%
将是有用的。 能否请你帮我如何与<% %>
写,我需要这样的:
The customer id is <%= Model.Id %> <br />
The customer Code is <%= Model.CustomerCode %> <br />
<% if (Model.Amount > 100) {%>
This is a priveleged customer
<% } else{ %>
This is a normal customer
<%} %>
但我能够使用这样才:
<div>
@{
if(Model.Amount > 70000.00)
{
Response.Write("This is a Privelleged Customer"); <br />
}
else
{
Response.Write("This is a Normal Customer"); <br />
}
}
The Customer Id is: @Model.Id <br />
The Customer Name is: @Model.Code <br />
</div>
这是因为您使用的渲染引擎是Razor。我认为,当您设置项目时,您可以选择使用哪个引擎。你可以在设置后做到这一点,看到这个所以发布在这里:http://stackoverflow.com/questions/16563811/changing-view-engine-after-project-has-been-created - 你会需要将其从* Razor更改为ASPX(需要一点互联网搜索才能满足您的需求) –
为什么在Razor代码中使用Response.Write?你不需要这样做。这就是你不喜欢剃刀的原因吗? – Liam
@Liam - 我认为这是OP用于写入ASPX视图引擎。为了克服不得不使用'Response.Write()'函数,你可以在大括号内写一些HTML标记 –