【发布时间】:2016-03-30 19:41:19
【问题描述】:
我有一个 MVC 视图,带有一个标签和两个单选按钮。 What I am trying to do is, when the radiobutton "Dark" is selected, the text color in the label should change to black and when the radiobutton "Light" is selected the text color should change to white.
型号:
public class SetupThemeModel
{
public bool IsFontColorDark { get; set; }
}
控制器:
public ActionResult LabelText(SetupThemeModel model)
{
return View(model);
}
查看:
@using (Html.BeginForm())
{
<label>
@Html.RadioButtonFor(m => m.IsFontColorDark, "false", new { id = "Light" })
@Html.Label("Light", "Light Font Color")
</label><br />
<label>
@Html.RadioButtonFor(m => m.IsFontColorDark, "true", new { id = "Dark" })
@Html.Label("Dark", "Dark Font Color")
</label>
<input type="submit" value="Try" class="btn btn-danger" />
}
还有标签:<h1><span class="label label-default h1" id="text" style="background-color:#ffd800">Sample Text</span></h1>
我试图通过标签 ID 传递颜色,但我被卡住了,我不知道如何继续。
【问题讨论】:
-
您应该使用
javascript或jQuery来执行此操作。
标签: asp.net-mvc razor radio-button