[英]passing data between controller methods
我正在創建asp.net mvc 5應用程序。 在此應用程序中,我遇到了在控制器方法之間傳遞數據的問題。
在這里,場景逐步
我正在像這樣將IEnumerable
數據集添加到Create_Brochure
方法
public ActionResult Create_Brochure(IEnumerable<ProductsPropertiesVM> model) { IEnumerable<BrochureTemplateProperties> sample = model.Where.... return View(sample); }
然后,我需要將該IEnumerable<ProductsPropertiesVM> model
保存到另一個IEnumerable
對象,並在Create_Brochure_PDF()
方法中使用它
public ActionResult Create_Brochure_PDF() { IEnumerable<BrochureTemplateProperties> samplePDF = modelPDF.... return View(samplePDF); }
為此,我做了R&D部分,並提出了Sessions的解決方案,在這里我遵循了該教程
所以我這樣改變了我的代碼
但是,盡管我按照教程的要求進行操作,但是我似乎在編譯時出現錯誤
第一控制器方法
[HttpPost]
[ValidateInput(false)]
public ActionResult Create_Brochure(IEnumerable<ProductsPropertiesVM> model)
{
IEnumerable<ProductsPropertiesVM> modelPDF = new IEnumerable<ProductsPropertiesVM>();
modelPDF = model;
IEnumerable<BrochureTemplateProperties> sample = model.Where(y => y.IsChecked)
.Select(y => new BrochureTemplateProperties
{
Property_ID = y.Property_ID,
IsChecked = y.IsChecked,
Property_Title = y.Property_Title,
Property_Value = y.Property_Value
});
TempData["TemplateData"] = modelPDF;
return View(sample);
}
第二控制器方法
public ActionResult Create_Brochure_PDF()
{
IEnumerable<ProductsPropertiesVM> modelPDF = TempData["TemplateData"] as IEnumerable<ProductsPropertiesVM>;
IEnumerable<BrochureTemplateProperties> samplePDF = modelPDF.Where(y => y.IsChecked)
.Select(y => new BrochureTemplateProperties
{
Property_ID = y.Property_ID,
IsChecked = y.IsChecked,
Property_Title = y.Property_Title,
Property_Value = y.Property_Value
});
return View(samplePDF);
}
您無法實例化接口..!
更換
IEnumerable<ProductsPropertiesVM> modelPDF = new IEnumerable<ProductsPropertiesVM>();
modelPDF = model;
同
IEnumerable<ProductsPropertiesVM> modelPDF = model;
在您的Create_Brochure
方法中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.