问题描述
我使用剃刀语法,我想检查,看看是否之前,我吐出了HTML的某些ViewBag值设置。如果设置的值,然后我想将它写出来的。如果不是我想要它做什么。
I'm using razor syntax and I want to check to see if certain ViewBag values are set before I spit out the html. If a value is set then I want to write it out. If not I want it to do nothing.
@if (ViewBag.UserExists != null)
{ Response.Write(String.Format("<h3>{0}</h3>", ViewBag.UserExists)); }
这似乎并没有正常工作。在code显示出来的另一个H2我上面的code以上的顶部。我有两个寄存器控制方法。一个是get和其他接受岗位。如果用户存在我设置需要被显示给用户一个ViewBag项目
This doesn't appear to be working correctly. The code shows up on top of another h2 I have above the code above. I have two register controller methods. One is the get and the other accepts the post. If the user exists I am setting a ViewBag item that needs to be displayed to the user.
感谢
推荐答案
不要使用的Response.Write。相反,这样做:
Don't use Response.Write. Instead do this:
@if (ViewBag.UserExists != null)
{
<h3>@ViewBag.UserExists</h3>
}
这篇关于Viewbag检查是否项目存在并写出HTML和值误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!