在mvc中重新加载模型

时间:2013-10-30 20:24:17

标签: asp.net-mvc

我想获得一些关于在mvc动作中重新加载模型的资格。例如:

我有一些班级模特:

public class PresentationItemModel()
{   
   public int Id { get; set; }
   public string Name { get; set; }
   public string Title { get; set; }
   public string Type { get; set; }
   public List<int> PresentationIdList { get; set; }
}

一些控制器动作:

public ActionResult PostAction(PresentationItemModel model)
{
   ...

   if(model.PresentationIdList == null)
   {
      model.PresentationIdList = new List<int>();
   }
   model.PresentationIdList.Add(model.Id);

   ...
   ...
   ...
}

public ActionResult PostAction(PresentationItemModel model) { ... if(model.PresentationIdList == null) { model.PresentationIdList = new List<int>(); } model.PresentationIdList.Add(model.Id); ... ... ... }

我可以多次调用 PostAction 方法,我想用所有id保存 model.PresentationIdList 结果。但每次我的PresentationIdList重新加载所有模型。但这是标准行为。

我能解决吗?

1 个答案:

答案 0 :(得分:1)

您需要做的就是从model

返回PostAction个对象
public ActionResult PostAction(PresentationItemModel model)
{
   ...

   if(model.PresentationIdList == null)
   {
      model.PresentationIdList = new List<int>();
   }
   model.PresentationIdList.Add(model.Id);

   ...
   ...
   ...

   return new ActionResult(model);
}