mardi 5 mars 2019

I have a list of viewmodel in another viewmodel. How can I pass parameter from action to controller?

I have a ViewModel containing a list of another ViewModel. I want to pass parameters to my controller. I can pass all viewmodel parameters but my list of second viewmodel is null.

This is my viewmodel:

public class Provider_Coupon_FullViewModel {
    public int pid { get; set; }
    public int cid { get; set; }
    public int crid { get; set; }
    public string opr_user { get; set; }
    public List<PackageDetailsViewModel> PackageDetails { get; set; }
}

public class PackageDetailsViewModel {
    public int packages_id { get; set; }
    public string package_title { get; set; }
}

And this is my razor page:

@model IList<myproject.Provider_Coupon_FullViewModel>
@using (Html.BeginForm())
{
    for (var i = 0; i < Model.Count; i++)
    {
    <div class="form-horizontal col-lg-12 col-md-12 col-sm-12 col-xs-12">           
        @Html.EditorFor(Model => Model[i].pid)
        @Html.EditorFor(Model => Model[i].cid)
        @Html.EditorFor(Model => Model[i].crid)

        /// I want show checkbox for list of viewmodel and pass value of them if check box checked
        @for (int j = 0; j < Model[i].PackageDetails.Count; j++)
        {
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 FormBox">
                <input type="checkbox" id=@Model[i].PackageDetails[j].packages_id name=@Model[i].PackageDetails[j].package_title value=@Model[i].PackageDetails[j].packages_id class="check">
                <label for="@Model[i].PackageDetails[j].packages_id">@Model[i].PackageDetails[j].package_title</label>
            </div> 
        }
        @for (int j = 0; j < Model[i].PackageDetails.Count; j++)
        {
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 FormBox">
                <input type="checkbox" id=@Model[i].PackageDetails[j].packages_id name=@Model[i].PackageDetails[j].package_title value=@Model[i].PackageDetails[j].packages_id class="check">
                <label for="@Model[i].PackageDetails[j].packages_id">@Model[i].PackageDetails[j].package_title</label>
            </div>
        }
    </div>
    }
}




Aucun commentaire:

Enregistrer un commentaire