Question

I'm looking for the best way to use the MVCCheckboxList library in this case:

2 MVCCheckboxlists with 2 different entities.

Example:

  1. MvccheckboxList a: checkbox 1, checkbox2. => Using Entity One
  2. MvccheckboxList b: checkbox 1, checkbox2, checkbox3 => Using Entity Two

Based on this link http://www.codeproject.com/Tips/613785/How-to-Use-CheckBoxListFor-With-ASP-NET-MVC

MvccheckboxList a and MvccheckboxList b works, seperated not in same view.

I've got already a direction solution: Using a viewmodel with 2 entities and use that like this way in my view.

@using MvcCheckBoxList.Model
@model PortPlus.Data.OpenErp.ViewModels.UnionCategoryViewModel
@using (Html.BeginForm("UnionCategoryLists", "Client", FormMethod.Post))
{
    <fieldset>
        <legend></legend>
        <section class="checkBoxListFor">
            <p>
                @Html.CheckBoxListFor(
            model => model.UnionVM.PostedUnions.OpenErpUnionIds,
            model => model.UnionVM.AvailableUnions,
            union => union.Id,
            union => union.Name,
            model => model.UnionVM.SelectedUnions,
            Position.Horizontal)
            </p>
        </section>

    </fieldset>
    <fieldset>
        <legend></legend>
        <section class="checkBoxListFor">
            <p>
                @Html.CheckBoxListFor(
            model => model.CategoryVM.PostedCategories.OpenErpCategoryIds,
            model => model.CategoryVM.AvailableCategories,
            category => category.Id,
            category => category.Name,
            model => model.CategoryVM.SelectedCategories,
            Position.Horizontal)
            </p>
        </section>

    </fieldset>
    <div>

        <button class="btn_portplus">@Html.ActionLink("Vorige","Index","Client")</button>
         <input class="btn_portplus" type="submit"
                        value="Volgende" />
    </div>
}

I've got my HTTPGET working, but my HTTPPOST ain't working, more specific is that i want to get the "model => model.CategoryVM.PostedCategories.OpenErpCategoryIds"/"model.UnionVM.PostedUnions.OpenErpUnionIds" values back to pass for database interaction, to save the new selected items. I need the "OpenErpCategoryIds" and "OpenErpUnionIds", only those values I need to get somehow but i don't know why it's not working.

Below my httpget and httppost (controller)

[HttpGet]
            public ActionResult UnionCategoryLists(Guid id)
            {
                var unionscategories = _openerpupdatebusiness.UniversalInitialModel(id);
                return View(unionscategories);
            }
            [HttpPost]
            public ActionResult UnionCategoryLists(Guid id,UnionCategoryViewModel uc)
            {
                var newselectedunionscategories = _openerpupdatebusiness.UniversalModel(id, uc);
                return RedirectToAction("CompanyContacts");
            }

Any help or better solution for my module are welcome!

Was it helpful?

Solution

I fixed it this way: (can't give you my code, only my idea that fixed it)

2 Entities 1 Viewmodel containing the 2 Entities and re-used the code from the link

That Viewmodel contains double PostedEntitieA, PostedEntitieB, AvailableEntitieA, B and so on, it's kind of duplicating in a sense but in my case it's the only way to fix it right know but if you have time over make it more clean.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top