【发布时间】:2023-03-26 01:07:01
【问题描述】:
尝试重新发布视图,但我想要的字段为空。
这是控制器...
public ActionResult Upload()
{
VMTest vm = new VMTest();
return View(vm);
}
[HttpPost]
public ActionResult Upload(VMTest vm, String submitButton)
{
if (submitButton == "Upload")
{
//do some processing and render the same view
vm.FileName = "2222"; // dynamic creation of filename
vm.File.SaveAs(@vm.FileName); // save file to server
return View(vm);
}
else if (submitButton == "Save")
{
//read the file from the server
FileHelperEngine engine = new FileHelperEngine(typeof(PaymentUploadFile));
PaymentUploadFile[] payments = (PaymentUploadFile[])engine.ReadFile(@vm.FileName); // the problem lays here @vm.FileName has no value during upload
//save the record of the file to db
return View("Success");
}
else
{
return View("Error");
}
}
我的视图中已经有一个@Html.HiddenFor(model => Model.FileName)。
但我仍然得到 Model.FileName 的空值。
请帮忙
谢谢
【问题讨论】:
标签: asp.net-mvc-3