私はおそらく私に代わって小さな見落としに直面していますが、ビューで複雑なクラスをシリアル化しようとしています。このコードを実行すると、循環参照を取得し続けます。
コントローラ:
public JsonResult EditPrice(int id)
{
Category cat = _categoryDataGateway.GetCategory(id);
return Json(new {category = cat}, JsonRequestBehavior.AllowGet);
}
Jquery:
<script type="text/javascript">
function PriceChange(e) {
if (e.name == "PriceCategory") {
var priceWindow = $("#PriceWindow").data("tWindow");
var category = e.response.category;
$("#PriceDetails")
.find("h2")
.text(category.Name);
priceWindow.center().open();
}
}
</script>
ビュー+テレリック:
<div>
@(Html.Telerik().Grid(Model)
.Name("CategoryList")
.Localizable("is-IS")
.Columns(columns =>
{
columns.Bound(o => o.Name).Width("20%");
columns.Bound(o => o.Id).Template(o => Html.Label(o.SuperCategory())).Title("Yfirflokkur").Width("15%");
columns.Bound(o => o.Description).Width("35%");
columns.Command(command =>
{
command.Custom("EditCategory").Text("Edit").Action("Edit", "Category").DataRouteValues(r => r.Add(k => k.Id));
command.Custom("PriceCategory").Text("Price").Action("EditPrice", "Category").DataRouteValues(r => r.Add(k => k.Id).RouteKey("Id")).Ajax(true);
command.Custom("DeleteCategory").Text("Delete").Action("Delete", "Category").DataRouteValues(r => r.Add(k => k.Id));
}).Width("30%").Title("Actions");
})
.ClientEvents(events => events.OnComplete("PriceChange"))
.Sortable()
.Footer(false)
)
</div>
<div>
@(Html.Telerik().Window()
.Name("PriceWindow")
.Visible(false)
.Title("Price")
.Modal(true)
.Width(500)
.Height(200)
.Content(@<text>
<div id="PriceDetails">
<h2></h2>
<div>
<input id="CategoryPrice" type="text"/>
</div>
<div>
<button>Submit</button>
</div>
</div>
</text>)
)
</div>
私の目標は、グリッドの[価格]ボタンを押すことができるようにすることです。ウィンドウがポップアップして、価格を変更できます。問題は、私はすでにこのコードを使用して単純な文字列をビューに送信することができ、それは完全に機能することです。たとえば、「cat」だけでなく「cat.Name」をコントローラーから送信するので、基本的に送信するとき複合型「Category」循環参照を取得します。
any1は私の失敗を見つけることができますか?:)