在剃刀视图中将模型数据添加到IEnumerable列表中,以传递回控制器

时间:2019-05-10 17:53:59

标签: c# asp.net razor model-view-controller

我的剃刀视图中有一个循环,可创建多个视图模型。我想将结果存储在列表中。

剃刀视图

 @foreach (var servOffer in Model.FilterServices.SelectedServicesNames)
        {
        <h4>@servOffer</h4>
        <div class="form-group">
            @Html.LabelFor(model => model.CustomerServices.ServiceRatePerNight, htmlAttributes: new { @class = "SerivcesRegistrationLabel control-label col-md-2" } )
            <div class="SerivcesRegistrationInput col-md-10">
                @Html.EditorFor(model => model.CustomerServices.ServiceRatePerNight, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.CustomerServices.ServiceRatePerNight, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.CustomerServices.SpacesAvailableEachDay, htmlAttributes: new { @class = "SerivcesRegistrationLabel control-label col-md-2" })
            <div class="SerivcesRegistrationInput col-md-10">
                @Html.EditorFor(model => model.CustomerServices.SpacesAvailableEachDay, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.CustomerServices.SpacesAvailableEachDay, "", new { @class = "text-danger" })
            </div>
        </div>
}

查看模型

 public class ServiceProvider
    {
        public CustomerProfile Customer { get; set; }

        public IEnumerable<CustomerProfile> CustomerProfiles { get; set; }
        public CustomerServices CustomerServices { get; set; }

        public IEnumerable<CustomerServices> CustomerServicesList { get; set; }

        public List<CustomerServices> ProviderServicesList { get; set; }

        public FilterServicesViewModel FilterServices { get; set; }

        public CustomerRating Rating { get; set; }

        public IEnumerable<CustomerRating> CustomerRating { get; set; }
    }

控制器

 public ActionResult CustomerServices(ServiceProvider data, string prevBtn, string nextBtn)
        {
}

数据不是由多个客户服务填充的,而是最后一个循环的。如何添加数据i

0 个答案:

没有答案