Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc mvc中的重载模型_Asp.net Mvc - Fatal编程技术网

Asp.net mvc mvc中的重载模型

Asp.net mvc mvc中的重载模型,asp.net-mvc,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> Pre

我想获得一些关于在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; }
}
公共类PresentationInModel()
{   
公共int Id{get;set;}
公共字符串名称{get;set;}
公共字符串标题{get;set;}
公共字符串类型{get;set;}
公共列表表示数据列表{get;set;}
}
以及一些控制器操作:

public ActionResult PostAction(PresentationInModel模型)
{
...
if(model.PresentationIdList==null)
{
model.PresentationIdList=新列表();
}
model.PresentationIdList.Add(model.Id);
...
...
...
}

我可以多次调用PostAction方法,我想保存模型。PresentationId列出所有id的结果。但每次我的演示列表都会重新加载所有模型。但这是标准行为


我能解决它吗

只需从
PostAction
返回
模型
对象即可:

public ActionResult PostAction(PresentationItemModel model)
{
   ...

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

   ...
   ...
   ...

   return new ActionResult(model);
}
public ActionResult PostAction(PresentationInModel模型)
{
...
if(model.PresentationIdList==null)
{
model.PresentationIdList=新列表();
}
model.PresentationIdList.Add(model.Id);
...
...
...
返回新的ActionResult(模型);
}

我知道英语可能不是你的第一语言,但试着把你的问题改写一下,让它更清楚。我会继续看它,试图找到答案。您的
PostAction
每次都会接受一个新的
PresentationInModel
。因此,如果你想在每篇文章中存储
id
s,你应该将它们存储在数据库中。我不应该保存到数据库。在最近的逻辑中,我做了,但我想改变它。
public ActionResult PostAction(PresentationItemModel model)
{
   ...

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

   ...
   ...
   ...

   return new ActionResult(model);
}