を経由して、私はいくつかのPartialViewsを含むASP.NET MVC 3のビューを持っています。そのうちの1人は、ViewModelのパラメータに依存するインターネットからのイメージを取得します。私はViewModelのパラメータを変更し、変更されたパラメータを持つ画像がロードされるようにそのPartialView(のみ)をリロードしたいと思います。リフレッシュMVC 3 PartialViewはJavaScriptを
はここで、これまでの私のPartialViewです:
@model MyViewModel
<script type="text/javascript">
function changeParameter(newValue) {
@Model.Parameter = newValue;
alert(@Model.Parameter);
... What now? How do I refresh the PartialView? ...
}
</script>
<h4>@Model.Header</h4>
<table style="background-color: #f8f7f8; width:100%;">
<tr style="line-height:18px; background-color: #d6d6d6;">
<th style="cursor:pointer" onclick="changeParameter('value1');">Value1</th>
<th style="cursor:pointer" onclick="changeParameter('value2');">Value2</th>
<th style="cursor:pointer" onclick="changeParameter('value3');">Value3</th>
<th style="cursor:pointer" onclick="changeParameter('value4');">Value4</th>
<th style="cursor:pointer" onclick="changeParameter('value5');">Value5</th>
<th style="cursor:pointer" onclick="changeParameter('value6');">Value6</th>
<th style="cursor:pointer" onclick="changeParameter('value7');">Value7</th>
</tr>
</table>
<img src="@Model.ImageUrl" alt="Chart" />
そうなことは、私は値(Value1-7)のいずれかをクリックしますと、私のViewModelのパラメータ変数が変更されていることです。 これまでのところ、アラートボックスに設定した値が表示されるため、動作します。 は、私は今、彼らは私が変更 パラメータに依存して@Model.Header
など@Model.ImageUrl
が更新されるようにPartialViewをリロードします。 どうすればいいですか? ああところで、私は...
乾杯、
サイモンJavaScriptに全く新たなんだ
EDIT:
[OK]を、2つの答えは、上記の少しを助けるでしたが、私はのようにこれまでのところ良いです
@model MyViewModel
<div id="my-header">
<h4>@Model.Header</h4>
</div>
<table id="my-table" style="background-color: #f8f7f8; width:100%;">
<tr style="line-height:18px; background-color: #d6d6d6;">
<th style="cursor:pointer" id="value1">Value1</th>
<th style="cursor:pointer" id="value2">Value2</th>
<th style="cursor:pointer" id="value3">Value3</th>
<th style="cursor:pointer" id="value4">Value4</th>
<th style="cursor:pointer" id="value5">Value5</th>
<th style="cursor:pointer" id="value6">Value6</th>
<th style="cursor:pointer" id="value7">Value7</th>
</tr>
</table>
<div id="my-image">
<img src="@Model.ImageUrl" alt="Chart" />
</div>
<script type="text/javascript">
$('#my-table th').click(function() {
alert(this.id);
@Model.Parameter = this.id;
$('#my-header').html("<h4>@Model.Header</h4>");
});
</script>
が、私はプロパティを操作するために管理することはできません:それは難しいのようなものだ本当のJavaScriptのnoobのは...
私が今持っていることですmy Modelクラスの。したがって、@Model.Parameter = anyValue;
のコールは機能しません。
JavaScriptでこれを行うにはどうすればよいですか?
EDIT 2: [OK]を、私は最終的にチャームが提案した方法で解決しました。 JSONの方法。
しかし、すべての可能なURLとヘッダはDictionary<string, string>
に格納されているように、私は私のViewModelを変更し、すべての最初の。それから私のPartialViewは次のとおりです。
@model MyViewModel
<div id="my-header">
<h4>@Model.Header</h4>
</div>
<table id="my-table" style="background-color: #f8f7f8; width:100%;">
<tr style="line-height:18px; background-color: #d6d6d6;">
<th style="cursor:pointer" id="value1">Value1</th>
<th style="cursor:pointer" id="value2">Value2</th>
<th style="cursor:pointer" id="value3">Value3</th>
<th style="cursor:pointer" id="value4">Value4</th>
<th style="cursor:pointer" id="value5">Value5</th>
<th style="cursor:pointer" id="value6">Value6</th>
<th style="cursor:pointer" id="value7">Value7</th>
</tr>
</table>
<div id="my-image">
<img src="@Model.ImageUrl" alt="Chart" />
</div>
<script type="text/javascript">
$('#my-table th').click(function() {
var urls = @Html.Raw(Json.Encode(@Model.Urls));
var url = urls[this.id];
$('#my-image').html("<img src='" + url + "' alt='Chart' />");
var headers = @Html.Raw(Json.Encode(@Model.Headers));
var header = headers[this.id];
$('#my-header').html(header);
});
</script>
それはあなたの努力のために...
おかげであることを意味して今すぐすべての作品。
私のEDITを見てください。たぶんあなたが私を助けることができます... –