私はMVCについてまったく新しいです。次のモデルクラスがあります。
public class Store
{
public PriceList PriceListInfo { get; set; }
public IStore storeData;
}
public class PriceList
{
public int id { get; set; }
public string codice { get; set; }
}
public interface IStore
{
[...]
}
public class Silo2Store : IStore
{
public int S2 { get; set; }
public int S3 { get; set; }
}
そして、私はこのモデルを私の見解で使用したいと思います:
@model Store
@Html.TextBoxFor(model => ((Silo2Store)Model.storeData).S3)
対応するControllerメソッドは次のとおりです。
public ActionResult Customer()
{
using (Store t = (Store)Session["Store"])
{
if (t.PriceListInfo == null)
{
t.PriceListInfo = new PriceList();
}
t.PriceListInfo.codice = "XXX";
return View(t);
}
}
そして、コントローラーでモデルを取得したいと思います。
[HttpPost]
public ActionResult Customer(Store modelStore)
{
var test = ((Silo2Store)Model.storeData).S3;
}
しかしModel.storeData
、私の見解では属性は初期化されていません。それはnull
です。次に、コントローラーで値を取得できません。
とにかくモデルを変更する必要がありますか?