0

我有一个wizardtype表单,我想将模型从第一步一直保存到最后。

这就是我现在的做法,但我似乎无法将模型从第 3 步保留到第 4 步。

[HttpPost]
public ActionResult Register(MemberViewModel model)
{
    var mobile = model.Mobile;
    var xml = MemberclubHelper.CreateVerificationTokenXML(mobile, "47");
    MemberclubHelper.SendVerificationToken(xml);
    return RedirectToAction("RegisterStep1", new { mobile = mobile });
}

public ActionResult RegisterStep1(string mobile)
{
    var model = new MemberViewModel();
    model.Mobile = mobile;
    return View("Register/Step1", model);
}

[HttpPost]
public ActionResult RegisterStep1(MemberViewModel model)
{
    var interests = (from interest in model.Interests where interest.isChecked select interest.value).ToList();
    var passing = (from pass in model.Passing where pass.isChecked select pass.value).ToList();

    var xml = MemberclubHelper.CreateMemberProfileXML(model.Mobile, model.FirstName, model.FirstName,
        model.Email1, model.Zipcode, model.SelectedKid1, model.SelectedKid2, model.SelectedKid3,
        model.Gender.ToString(), interests, passing);
    model.XmlToSend = xml;
    if (xml.Contains("error"))
    {
        model.ErrorMessage = xml;
        return View("Register/Step1", model);
    }

    return View("Register/Step2", model);
}

[HttpPost]
public ActionResult RegisterStep2(MemberViewModel model)
{
    var result = MemberclubHelper.SendCreateUser(model.XmlToSend, model.Password);
    if (result.Contains("error"))
    {
        model.ErrorMessage = result;
        return View("Register/Step2", model);
    }

    else
    {
        return View("Register/Finished");
    }
}
4

1 回答 1

0

我认为为每个步骤创建一个单独的视图模型(即 MemberViewModelStep1)可能会更好地为您服务。对我来说,这似乎只有您的一些 MemberViewModel 属性将在每个步骤中设置,除非您通过隐藏输入或其他机制在步骤之间携带大量该状态。

或者,您是否考虑过使用 JavaScript 在您的步骤之间建立该状态,然后使用完全填充的 MemberViewModel 提交单个帖子?

于 2013-02-03T19:45:08.617 回答