在MVC中,如何才能让默认选中的复选框的这个例子吗? [英] In MVC, how can I make this example of a checkbox checked by default?
问题描述
我试图在MVC中的复选框被默认选中。
下面是我的code。因为我已经看到了这一切的例子,该人使用的东西比我想,所以我一直没能找到有关这种帮助却不同。
<%= Html.CheckBoxFor(功能(模型)model.Delete)%>
我曾尝试加入,新{@checked =检查}
办法并没有工作。我下波浪线的第一个{......整条生产线看起来像这样...
<%= Html.CheckBoxFor(功能(模型)model.Delete,新{@checked =选中}))%>
我如何能得到这个复选框任何意见,可自动检查?
感谢您的帮助组。
威尔
这是我使用我的控制器是什么。这是CONTROLER的开始......这是不行的。 FirstNameAsBusiness是复选框的名字
在视图...
<%= Html.CheckBoxFor(功能(模型)model.FirstNameAsBusiness)%> <%= Html.LabelFor(功能(模型)model.FirstNameAsBusiness)%>
在控制器....
功能编辑(BYVAL一个作为AuditModel)作为的ActionResult
a.FirstNameAsBusiness = TRUE
返回查看(一)
端功能
你尝试
<%= Html.CheckBoxFor(功能(模型)model.Delete,新增功能{.checked =选中})%>
唯一的其他东西我能想到的是做的SLaks已建议。
功能编辑(BYVAL一个作为AuditModel)作为的ActionResult
a.FirstNameAsBusiness = TRUE
a.Delete = TRUE''#这应该这样做。
返回查看(一)
端功能
查看
<%= Html.CheckBoxFor(功能(模型)model.Delete)%>
I am trying to make a checkbox in MVC be checked by default.
Below is my code. For all examples I have seen of this, the person uses something different than what I am trying so I have not been able to find help on this yet.
<%=Html.CheckBoxFor(Function(model) model.Delete)%>
I have tried adding the , new { @checked = "checked" }
approach and that didnt work. I got a squiggly line under the first "{".... the entire line looked like this...
<%=Html.CheckBoxFor(Function(model) model.Delete, new { @checked = "checked" }))%>
Any advice on how I can get this checkbox to be auto checked?
thanks for any help group.
Will
This is what I am using in my controller. This is the start of the COntroler... this is not work. FirstNameAsBusiness is the name of the checkbox
In the view...
<%=Html.CheckBoxFor(Function(model) model.FirstNameAsBusiness)%> <%=Html.LabelFor(Function(model) model.FirstNameAsBusiness)%>
In the controller....
Function Edit(ByVal a As AuditModel) As ActionResult
a.FirstNameAsBusiness = True
Return View(a)
End Function
Did you try
<%=Html.CheckBoxFor(Function(model) model.Delete, New With { .checked = "checked" })%>
The only other thing I can think of is to do as SLaks has suggested.
Function Edit(ByVal a As AuditModel) As ActionResult
a.FirstNameAsBusiness = True
a.Delete = True ''# This should do it.
Return View(a)
End Function
View
<%=Html.CheckBoxFor(Function(model) model.Delete)%>
这篇关于在MVC中,如何才能让默认选中的复选框的这个例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!