部分的なビューとdisplay/editortemplatesおよびKendouiを利用するasp.netmvc4アプリケーションを構築しようとしています。特定のページのビューモデルがあります。
public class Plant {
public Guid PlantId{ get; set; }
public string Name { get; set; }
public string Description { get; set; }
public ICollection<Leaf> Leafs{ get; set; }
public ICollection<Flower> Flowers{ get; set; }
public ICollection<Bug> Bugs{ get; set; }
}
また、葉、虫としての花には独自の特性があります。例:
public class Leaf {
public Guid LeafId{ get; set; }
public string Name { get; set; }
public string Documentation { get; set; }
public string Description { get; set; }
}
ビューで部分ビューを使用しているので、ajaxでの更新がより簡単になります。私の通常のビュー:PlantDetail.cshtml
@model Plant
<table>
<tr>
<td>
<h2>@Html.Label(Resources.PlantDetailTitle)</h2>
</td>
<td>
@Html.HiddenFor(m => m.PlantId)
@Html.DisplayFor(m => m.Name)
</td>
</tr>
<tr>
<td>@Html.LabelFor(m => m.Description)
</td>
<td>
@Html.DisplayFor(m => m.Description)
</td>
</tr>
</table>
@{Html.RenderPartial("_flowers", Model);}
@{Html.RenderPartial("_leafs", Model);}
私の部分ビュー「_leafs」(および「_flowers」)には、LeafIdとPlantIdを必要とするアクションを呼び出す一連のボタンがあります。
部分ビュー"_leafs":
@model List<Leaf>
@for (int i = 0; i < Model.Count(); i++ )
{
@(Html.DisplayFor(m => m[i]))
}
私のdisplayTemplate"Leaf.cshtml":
@model Leaf
@Html.HiddenFor(m =>m.LeafId)
<a class='k-button k-button-icontext' href=@Url.Action("InitiateLeaf", "Plant") +"?
leafId=@Model.LeafId&plantId=#=PlantId#">@Model.Name</a>
今、私の問題は、displaytemplateで親ビューモデルのPlantIdにアクセスできないように見えることです。(そして、各displaytemplatesで同じ問題が発生します。)url.actionのroutevaluesですでに試しましたが、最終的にjavascriptでPlantIdにアクセスできることはわかっていますが、(mvc)方法はありますか? displaytemplatesを使い続け、私のplantIdを子のLeafビューモデルのプロパティとして複製しませんか?
私はすでに、displaytemplateで「@ HttpContext.Current.Request.RequestContext.RouteData.Values ["controller"]。ToString()」のようなものでparentviewcontextにアクセスしようとしましたが、私の値が見つからないようですPlantId(そこに保存されている場合でも..)。
他の誰かがまだいくつかの提案がありますか?