简体   繁体   English

ASP.NET / MVC:内联代码

[英]ASP.NET/MVC: Inline code

What am I doing wrong? 我究竟做错了什么? How come <%= this %> isn't being interpreted as C#? 为什么<%= this %>没有被解释为C#?

Here's the code : 这是代码: 主持者imgur.com

And here is what it renders (notice the Firebug display): 这是它呈现的内容(注意Firebug显示): 主持者imgur.com

What do you think is going on? 你觉得怎么样? MVC newb here. MVC newb在这里。 :( :(

And the static Site class: 和静态Site类: 主持者imgur.com

(If you cannot see the screenshots on the page, view source and use the URLs from the <img> tags.) (如果您无法在页面上看到屏幕截图,请查看源并使用<img>标记中的URL。)

<%: %> starts with .NET v4 <%: %>以.NET v4开头

For pre-v4 it's equivalent is <%= Html.Encode(...) %> 对于pre-v4,它相当于<%= Html.Encode(...) %>

问题是我在runat =“sever”的标签中使用<%=%>(甚至<%:%>)。

Shouldn't that be <% %> or <%= %> for a shorthand of Response.Write? 对于Response.Write的简写,不应该是<% %><%= %>吗?

Here's an MSDN article on Embedded Code Blocks . 这是关于嵌入式代码块的MSDN文章。

This sometimes happens to me when embedding code inside of html attributes. 当在html属性中嵌入代码时,这有时会发生在我身上。 I've never quite pinned down the exact cause but sometimes you can get around it by using single quotes rather than double. 我从来没有完全确定原因,但有时你可以通过使用单引号而不是双引号绕过它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM