我对 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
. 然后,我无法检索控制器中的值。
无论如何我应该改变我的模型吗?