Razor 如何创建 CheckBox 并使其成为 READONLY? [英] Razor how to create a CheckBox and make it READONLY?
本文介绍了Razor 如何创建 CheckBox 并使其成为 READONLY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 MVC 3 和 Razor
I'm using MVC 3 and Razor
目前我正在使用
@model MyProject.ViewModels.MyViewModel
@foreach (var item in Model.MyProperty)
{
<tr>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.AdvSlotId }) |
@Html.ActionLink("Details", "Details", new { id = item.AdvSlotId }) |
@Html.ActionLink("Delete", "Delete", new { id = item.AdvSlotId })
</td>
<td>
@item.AdvSlotId
</td>
<td>
@item.Name
</td>
<td>
@item.Description
</td>
<td>
@Html.CheckBox(item.IsPublished, new { @disabled = "disabled" })
</td>
<td>
@item.Notes
</td>
</tr>
}
视图模型:
namespace MyProject.ViewModels
{
public class MyViewModel
{
public MyViewModel(List<AdvSlot> advSlots)
{
MyProperty= advSlots;
}
public List<AdvSlot> MyProperty { get; set; }
}
}
在我的模型中显示属性的复选框.因为我做的是错误的所以我只能显示像 TRUE 这样的文本.
To display a Check Box for a property in my Model. As I'm doing is wrong so I can only display a text like TRUE.
你能告诉我如何用 Razor 创建 CheckBox 吗?我还需要将其设为 READONLY.
Could you please tell me how to create the CheckBox with Razor? I would also need have it as READONLY.
感谢您的帮助.
推荐答案
应该是这样的:
@Html.CheckBoxFor(m => m.IsPublished, new { @disabled = "disabled" })
更新:
假设您的类 AdvSlot
包含一个属性 IsPublished
,您可以在循环中编写:
Assuming that your class AdvSlot
contains a property IsPublished
you can write in your loop:
<td>
@Html.CheckBox(item.AdvSlotId + "_IsPublished", item.IsPublished, new { @disabled = "disabled" });
</td>
这篇关于Razor 如何创建 CheckBox 并使其成为 READONLY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文