asp.net-mvc-3 – Razor in-line if语句不工作?

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-3 – Razor in-line if语句不工作?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个异常抛出这一行,不能弄清楚为什么…也许有人可以发现它
<img src="@{Model.Image != null ? Model.Image.FileName : "";}" width="200px" id="ImagePreview"/>

我得到的例外是:

error CS0201: Only assignment,call,increment,decrement,and new object expressions can be used as a statement

解决方法

@H_502_11@ 您需要为该表达式使用表达式(显式)代码块样式:
<img src="@(Model.Image != null ? Model.Image.FileName : "")" width="200px" id="ImagePreview"/>

gu’s post

原文链接:https://www.f2er.com/aspnet/254198.html

猜你在找的asp.Net相关文章