1
複数のモデルを処理するための剃刀ビューの最良の方法は何ですか? MVC3アプリケーション用。Razorビューの複数のビューモデル
は、私は2つのモデルがあり、両方似ていますが、郵便番号フィールドがなく、私は私が渡されています国に応じて特定のビューモデルを使用したいコントローラで別の
public class IrelandPostcodeLookupViewModel , IWithProgress
{
readonly Progress _Progress = new Progress(Step.Delivery);
public Progress Progress
{
get { return _Progress; }
}
[Required(ErrorMessage = "Please enter your house number or name")]
[DisplayName("House number or name")]
public string HouseNumber { get; set; }
[StringLengthWithGenericMessage(50)]
[DisplayName("Eircode")]
public string Postcode { get; set; }
}
public class PostcodeLookupViewModel , IWithProgress
{
readonly Progress _Progress = new Progress(Step.Delivery);
public Progress Progress
{
get { return _Progress; }
}
[Required(ErrorMessage = "Please enter your house number or name")]
[DisplayName("House number or name")]
public string HouseNumber { get; set; }
[StringLengthWithGenericMessage(50)]
[Required(ErrorMessage = "Please enter your postcode")]
[DisplayName("PostCode")]
public string Postcode { get; set; }
}
のために一つのモデルに必要とされます。 「
@model dynamic
私はこれを持っている問題で、私はビューでこれを処理していた
public virtual ActionResult PostcodeLookup(string country)
{
if (country == Country.UnitedKingdom)
return View(new PostcodeLookupViewModel());
else
return View(new IrelandPostcodeLookupViewModel());
}
ような何かが私の見解では、部分的なビュー
@Html.Partial("~/Views/Shared/_Progress.cshtml", Model.Progress)
が含まれていると私はエラーに遭遇しますHtmlHelper 'には' Partial 'という名前の適用可能なメソッドはありませんが、その名前で拡張メソッドがあるようです。拡張メソッドを動的にディスパッチすることはできません。 '
パーシャルビューをどのように処理できるかアドバイスできますか?
おかげ