使用ValidationSummary()
时,我在初始创建时看到Name
所需的错误。
我已经尝试在构造函数中初始化Name=""
而不是初始化(来自Name=null
) - 同样的结果。
如何让ValidationSummary()
不显示此字段的初始错误?
public class Scenario
{
public Int32 ID { get; set; }
//user input
[Required]
[DisplayName("Scenario Name")]
public String Name { get; set; }
[Required]
[DisplayName("Location")]
public Int32 LocationId { get; set; }
//..lots more, but omitted for question length
// GET: Scenario/Create
public ActionResult Create(Scenario copyFrom = null)
{
var vm = new EditScenarioViewModel
{
scenario = copyFrom ?? new Scenario(User.Identity.Name),
};
var periods = _performancePeriods.GetPeformancePeriodsHistory().ToList();
vm.scenario.FiscalPeriodStarting = periods.ElementAt(2).PerformancePeriodID; //default is 3rd period back
vm.scenario.FiscalPeriodEnding = periods.ElementAt(0).PerformancePeriodID;
vm = PrepareDropdowns(vm);
return View(vm);
}
答案 0 :(得分:1)
而不是传递参数使用TempData:
copyMe.ID = 0; //reset ID
TempData["CreateCopy"] = copyMe
return RedirectToAction("Create");
没有参数的Create():
public ActionResult Create()
{
scenario = TempData["CreateCopy"] as Scenario;
if (scenario == null)
{
scenario = new Scenario(User.Identity.Name);
}