我希望根据包含在html对象中的一些变量使用razor语法显示一些ViewBag内容。当前内容中断到条件语句之后的换行符。这就是我所拥有的:
<h5>Apply salary @ViewBag.salaryStatus to associated objects?</h5>
@if (ViewBag.salaryStatus == "Executed")
{
<h5>(This will overwrite old values of the selected objects).</h5>
}实际结果是:
Apply salary reviewed to associated objects?
(This will overwrite old values of the selected objects).预期结果是:
Apply salary reviewed to associated objects? (This will overwrite old values of the selected objects).发布于 2015-06-05 19:57:10
您正在添加多个H5元素。这些是块HTML元素,默认情况下将放在新行上。您应该只创建一个H5元素,如下所示:
<h5>Apply salary @ViewBag.salaryStatus to associated objects?
@if (ViewBag.salaryStatus == "Executed")
{
<text>(This will overwrite old values of the selected objects).</text>
}
</h5>发布于 2015-06-05 20:05:30
你也可以使用下面的逻辑;
@{
var message = "";
if () {
message = "your message";
}
}
<h5>Apply salary @ViewBag.salaryStatus to associated objects? @message</h5>https://stackoverflow.com/questions/30674719
复制相似问题