2

MVC のチェックボックスをデフォルトでチェックしようとしています。

以下は私のコードです。これについて私が見たすべての例で、その人は私が試みているものとは異なるものを使用しているため、まだこれに関するヘルプを見つけることができませんでした.

<%=Html.CheckBoxFor(Function(model) model.Delete)%>

, new { @checked = "checked" }アプローチを追加しようとしましたが、うまくいきませんでした。最初の「{」の下に波線ができました....行全体はこのように見えました...

<%=Html.CheckBoxFor(Function(model) model.Delete, new { @checked = "checked" }))%>

このチェックボックスを自動チェックする方法について何かアドバイスはありますか?

ヘルプグループに感謝します。

意思

これは私がコントローラーで使用しているものです。これはコントローラーの開始です...これは機能しません。FirstNameAsBusiness はチェックボックスの名前です

ビューで...

<%=Html.CheckBoxFor(関数(モデル) モデル.FirstNameAsBusiness)%> <%=Html.LabelFor(関数(モデル) モデル.FirstNameAsBusiness)%>

コントローラーで……

Function Edit(ByVal a As AuditModel) As ActionResult
    a.FirstNameAsBusiness = True 
    Return View(a)
End Function
4

3 に答える 3

1

試しましたか

<%=Html.CheckBoxFor(Function(model) model.Delete, New With { .checked = "checked" })%>

私が考えることができる唯一の他のことは、SLaksが提案したようにすることです.

Function Edit(ByVal a As AuditModel) As ActionResult
    a.FirstNameAsBusiness = True 
    a.Delete = True ''# This should do it.
    Return View(a)
End Function

意見

<%=Html.CheckBoxFor(Function(model) model.Delete)%>
于 2011-02-08T19:06:17.663 に答える
0

model.Deletetrueに設定する必要があります。

EDIT:呼び出す前に設定する必要がありますCheckbox

于 2011-02-08T19:01:36.250 に答える
-1

You could always just set the 'Delete' property to true on the constructor of your model (therefore the default value).

Very similar to what has been suggested above but this way no matter where you use the 'Delete' property it will always be ticked by default.

It all depends on if this is classed as business logic or more a View specific decision.

于 2011-02-09T00:14:33.487 に答える