私のプロジェクトで繰り返しコードの量を最小限に抑えようとしています。多くのビューは、ビューモデルのデータを要約しています。ビューモデルは、かなりモジュラーなデータを抽象化します。このようなものを表示するときは、モジュラー物の構造は常に同じですが、テキストは表示テンプレートをホストするビューによって変わります。私が持っているかもしれないセクション1でそう...asp.net mvc ascxファイルの場所に基づいてディスプレイテンプレートのリソースファイルを関連付けます
:
public class Section1ReportViewModel{
[UiHint("Person")]
[Display(ResourceType = typeof(Resources.Section1), Name="ReportedPerson")]
public Person ReportedPerson {get; set; }
[UiHint("Address")]
[Display(ResourceType = typeof(Resources.Section1), Name="HomeAddress")]
public Address HomeAddress {get; set; }
[UiHint("Person")]
[Display(ResourceType = typeof(Resources.Section1), Name="AssociatedPerson")]
public Person AssociatedPerson {get; set; }
}
ビュー/ 1節/ index.aspxのレポートビューが続いている可能性がありますでしょう:
MVCは共有で見ることができ@Model Section1ReportViewModel
@Html.DisplayFor(x=>x.ReportedPerson)
@Html.DisplayFor(x=>x.HomeAddress)
@Html.DisplayFor(x=>x.AssociatedPerson)
を/ DisplayTemplatesフォルダを使用して、UiHint属性を使用して表示テンプレートを取得します。私は第2節で、すべてのビューやものを再作成を行っていないように
さて、私が持っているでしょう:
public class Section2ReportViewModel{
[UiHint("Person")]
[Display(ResourceType = typeof(Resources.Section2), Name="ReportedPerson")]
public Person ReportedPerson {get; set; }
[UiHint("Address")]
[Display(ResourceType = typeof(Resources.Section2), Name="HomeAddress")]
public Address HomeAddress {get; set; }
[UiHint("Person")]
[Display(ResourceType = typeof(Resources.Section2), Name="AssociatedPerson")]
public Person AssociatedPerson {get; set; }
}
とビュー/ 2章/ index.aspx
でビューをと表示テンプレート(Person.ascx)のうちの一つの例として、
@Model Section1ReportViewModel
@Html.DisplayFor(x=>x.ReportedPerson)
@Html.DisplayFor(x=>x.HomeAddress)
@Html.DisplayFor(x=>x.AssociatedPerson)
:
@Model Person
<h1>@Html.Resource("Title")</h1>
<dl>
@Html.DetailLineFor(x=>x.FullName)
@Html.DetailLineFor(x=>x.DateOfBirth)
</dl>
は今...ここにパズルです。私はこれらの共有ビューをShared/DisplayTemplatesフォルダに保存します。しかし、Shared/DisplayTemplates/App_LocalResourcesフォルダにそれらのリソースファイルを保存したくありません。リソースファイルをViews/Section2/DisplayTemplates/App_LocalResources/Person.ascx.resxに保存したい
理由は、h1タグのテキストがセクション2に固有であり、同じテンプレートがセクション1 Views/Section1/DisplayTemplates/App_LocalResources/Person.ascx.resxのテキストが使用されます。
これを行う方法はありますか?私は自分の頭の中で、このようなものの検索パスはそれを処理できるとは思っていましたが、明らかにそうではありませんでした:(