1

所以我有这个页面,用户可以在其中选择两个不同类别(案例和当事人)的项目。当用户创建访问(计划)时,他们可以从“案例”类别中选择一个或多个项目并选择某些参与方。然后他们根据选择保存信息。当我转到此创建的时间表的编辑页面时,我希望为在创建页面期间选择和保存的项目标记复选框。我不确定我是否错过了传递的参数或我需要显示所选项目的内容。

我的 Create Get & Post Code(保存包含选择的信息)

[HttpGet]
    public ActionResult Create(Guid caseId)
    {
        var viewModel = new VisitViewModel();
        SetCaseFields(caseId, viewModel);
        viewModel.Time = _defaultVisitTime;
        AddLookupsToViewModel(viewModel);
        return View(viewModel);

    }

[HttpPost]
    public ActionResult Create(VisitViewModel viewModel, Guid[] associatedCasesSelected, Guid[] selectedParties)
    {
        if (!ModelState.IsValid)
        {
            viewModel.Time = _timeEntryHelper.Value;
            AddLookupsToViewModel(viewModel);
            return View(viewModel);
        }
        VisitEntry dto = Mapper.Map<VisitViewModel, VisitEntry>(viewModel);
        dto.VisitDate = _timeEntryHelper.AddTimeToDate(dto.VisitDate);
        dto.CasePartyIds = selectedParties;
        dto.Cases = associatedCasesSelected;
        SetCurrentUserAndOffice(dto);
        try
        {
            _visitEntryService.Create(dto, dto.Cases);
            this.FlashInfo(string.Format(Message.ConfirmationMessageCreate, Resources.Entities.Visit.EntityName));
        }
        catch (RulesException ex)
        {
            ex.CopyTo(ModelState);
        }
        if (ModelState.IsValid)
            return RedirectToAction("Edit", "Case", new { caseId = viewModel.CaseId });
        return View(viewModel);
    }

这是我的编辑获取和发布方法。

[HttpGet]
    public ActionResult Edit(Guid visitEntryId)
    {
        VisitEntry dto = _visitEntryService.Get(visitEntryId);
        if (dto == null) return View("Error");
        VisitViewModel viewModel = Mapper.Map<VisitEntry, VisitViewModel>(dto);
        SetCaseFields(dto.CaseId, viewModel);
         AddLookupsToViewModel(viewModel);
        return View(viewModel);}

[HttpPost]
        public ActionResult Edit(VisitViewModel viewModel, Guid[] associatedCasesSelected, Guid[] selectedParties)
        {
            if(!ModelState.IsValid)
            {
                viewModel.Time = _timeEntryHelper.Value;
                AddLookupsToViewModel(viewModel);
                return View(viewModel);
            }

            try
            {
                VisitEntry dto = Mapper.Map<VisitViewModel, VisitEntry>(viewModel);
                dto.VisitDate = _timeEntryHelper.AddTimeToDate(dto.VisitDate);
                dto.CasePartyIds = selectedParties;
                dto.Cases = associatedCasesSelected;
                SetCurrentUserAndOffice(dto);
                _visitEntryService.Update(dto, dto.Cases);
            }
            catch (RulesException ex)
            {
                ex.CopyTo(ModelState);
            }

            if (!ModelState.IsValid)
            {
                viewModel.Time = _timeEntryHelper.Value;
                AddLookupsToViewModel(viewModel);
                return View(viewModel);
            }
            this.FlashInfo(string.Format(Message.ConfirmationMessageUpdate, Kids.Resources.Entities.Visit.EntityName));
            return RedirectToAction("Edit", "Case", new {caseId = viewModel.CaseId});

        }

此方法加载聚会信息:

IList<Party> caseParties =
            _associatedCasePartyService.GetAssignedPartiesForThisAndAssociatedCases(viewModel.CaseId,
                                                                                    _currentUser.OfficeId);
        if (caseParties != null)
            viewModel.AvailableCaseParties = caseParties;

这是我的视图模型:

public class VisitViewModel 
{
    public IEnumerable<Party> AvailableCaseParties { get; set; }
    public IList<Guid> PartiesSelected { get; set; }
}

VisitForm.ascx 包含字段展示位置:

<%Html.RenderPartial("Parties", Model); %>

Party.ascx - 包含允许选中该框的行,完成后编辑条目,页面加载所有保存的信息,除了选中的各方:

 <% if (Model.AvailableCaseParties != null && Model.AvailableCaseParties.Count() > 0)
     {%>
         <div class="row">
         <fieldset>
         <legend>Parties</legend>
         <div>
                                            <%=Html.Grid(Model.AvailableCaseParties).Attributes(id => "PartiesGrid").Columns(
         column =>
           {
             column.For(party =>
             string.Format("<input type='checkbox' {1} name='selectedParties' value='{0}'/>",
                                                                                 party.PartyId, Model.PartiesSelected != null &&  Model.PartiesSelected.Count(p => p == party.PartyId) > 0 ? "checked" : string.Empty)).Encode(false).Header(string.Format("<TH><input type='checkbox' name='checkSelect'/></TH>"));

         column.For(party => party.FullName).Named(Kids.Resources.Entities.Party.EntityName);
                                                    }
                                                                  ).Empty(string.Format("No {0}", Kids.Resources.Entities.Party.EntityNamePlural))
                  %>
               </div>
          </fieldset>
     </div>
4

0 回答 0