如何分配一個匿名類型的模型? 使用ViewBag我可以輕鬆地分配這樣的:如何將匿名類型分配給模型?
ViewBag.certType = comboType.ToList();
我從我的系統中刪除所有ViewBags,現在我想這樣的:
我收到以下錯誤:
Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>'
to 'int' S:\Projects\tgpwebged\tgpwebged\Controllers\AdminController.cs
376 40 tgpwebged
型號:
public class TipoDocumentoModel
{
public sistema_DocType Type { get; set; }
public IEnumerable<string> Indices { get; set; }
public IEnumerable<string> NonAssoIndices { get; set; }
public int storeLocations { get; set; }
}
控制器:
public ActionResult AdminSettingAddTipo()
{
SettingsModels.TipoDocumentoModel model = new SettingsModels.TipoDocumentoModel();
//Pega os indices e locais de armazenamentos cadastrados no sistema
using (tgpwebgedEntities context = new tgpwebgedEntities())
{
var obj = from u in context.sistema_Indexes select u.idName;
model.Indices = obj.ToList();
var comboType = from c in context.sistema_Armazenamento
select new
{
id = c.id,
local = c.caminhoRepositorio
};
model.storeLocations = comboType.ToList();
}
return PartialView(model);
}
INT店位置!=列出某種類型 –
的這是一個完全合理的問題是問......但不是您所提供的例子。該示例有一個相當明顯的錯誤,與ViewBag,MVC甚至匿名類型無關。 – Bobson