私はとしてレンダリング部分図があります:私はisSelected
キーのこの値を変更し、チェックボックスが選択されているかどうかに基づいて、それをtrueまたはfalseを割り当てる必要がイベントに基づいてViewDataDictionaryで変数を割り当てる方法は?
<div>
@Html.Partial("/_PartialView.cshtml", null, new ViewDataDictionary { { "ControllerName", "Controller1" }, { "Attribute1", Model.Attribute1 }, { "Attribute2", Model.Attribute2 }, { "isSelected", "isTrue" } })
</div>
を。
$('#checkBox1').click(function() {
if ($('#checkBox1').is(':checked')) {
// set isSelected to true here
} else {
// set isSelected to false here
});
どのように私は_PartialView.cshtml
で、isSelected
の値を設定し、それに応じて異なる部分のビューをレンダリングすることができますか?この値を何らかの形でtrueまたはfalseに設定できる場合は、単にif
条件を使用して、選択したhtml要素を非表示または表示できます。
ありがとうございました。
編集:
これは私が一部の変数にアクセスしています方法です。 HTMLコードの
@{
var att1 = (int)ViewData["Attribute1"];
var att2= (int)ViewData["Attribute2"];
var controller = (string)ViewData["ControllerName"];
var isSelected = (bool)ViewData["isSelected"];
}
パート:
<div>
<li>
<button><span class="glyphicon glyphicon-upload"></span> Upload </button>
</li>
<li>
<button><span class="glyphicon glyphicon-upload"></span> Download </button>
</li>
@if(isSelected)
{
@*Display this button*@
<li>
<button><span class="glyphicon glyphicon-upload"></span> Delete </button>
</li>
}
</div>
部分的に出力されるHTMLを投稿できますか? – evolutionxbox
JSを介してサーバー上で実行される 'isSelected'変数を変更することはできません。できることは、クライアントサイドコード内のサーバー上のパーシャルのレンダリングに及ぼす影響を模倣することだけです。私たちは部分の内容を見る必要があります –
MVCの仕組みを誤解していると思います... ViewDataのようなサーバーサイドのオブジェクトは、ページのレンダリング中にのみ使用できますが、clickイベントはこの後になります...クリック後に部分ビューをレンダリングするためにajax呼び出しを使用したいと思うかもしれません... http://api.jquery.com/jquery.ajax/ – Milney