【问题标题】:Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement in radio button只有 assignment、call、increment、decrement、await 和 new 对象表达式可以用作单选按钮中的语句
【发布时间】:2016-02-07 02:59:06
【问题描述】:

只有赋值、调用、递增、递减、等待和新对象表达式可以用作语句。

如何在其中添加空格和文本

if (ViewBag.Institution == "Male")
{
  <input type="radio" id="male" name="male" checked="checked"  />&nbsp; Male &nbsp;
  <input type="radio" id="female" name="male" />&nbsp; Female &nbsp;
}

【问题讨论】:

  • 将文本包装在一个 span 元素中并给它一些填充
  • 同意@StephenMuecke,您应该使用 HTML/CSS 来解决您的布局问题。

标签: html asp.net-mvc asp.net-mvc-4 model-view-controller


【解决方案1】:

问题是角度标签之外的非中断空格,razor 将它们解释为代码。

试试这个:

if (ViewBag.Institution == "Male")
{
    <text>
        <input type="radio" id="male" name="male" checked="checked"  />&nbsp; Male &nbsp;
        <input type="radio" id="female" name="female" />&nbsp; Female &nbsp;
    </text>
}

Razor 现在会将完整的字符串视为文本。也修复了代码中看起来像是拼写错误的问题,除非您希望所有收音机的值都为 male

【讨论】:

  • name 属性必须相同,否则它不能作为单选按钮组工作——只是代码是无意义的,不会做任何事情。单选按钮需要value 属性,所以它应该类似于name="gender" value="male"name="gender" value="female" :)
猜你喜欢
  • 2013-07-23
  • 2013-02-18
  • 2021-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多