如何使用jQuery Repeater在MVC控制器中获取动态文本框值

时间:2019-04-21 16:38:17

标签: javascript jquery asp.net arrays asp.net-mvc

我使用jquery中继器,在jquery mvc中得到jquery动态文本框或文件上传值。那是我使用div中继器的代码如何获取值。我看到了追加文本框的内容,但是我想使用jQuery转发器来做到这一点。 我该怎么做。 在这里,我将数组用作要在控制器中传递值的字符串。

@{
    ViewBag.Title = "Index";
}
<div class="m-grid__item m-grid__item--fluid m-grid m-grid--ver-desktop m-grid--desktop m-container m-container--responsive m-container--xxl m-container--full-height">
    <div class="m-grid__item m-grid__item--fluid m-wrapper">

        <!-- BEGIN: Subheader -->
        <div class="m-subheader ">
            <div class="d-flex align-items-center">
                <div class="mr-auto">
                    <h3 class="m-subheader__title m-subheader__title--separator">Form Builder</h3>
                    <ul class="m-subheader__breadcrumbs m-nav m-nav--inline">
                        <li class="m-nav__item m-nav__item--home">
                            <a href="#" class="m-nav__link m-nav__link--icon">
                                <i class="m-nav__link-icon la la-home"></i>
                            </a>
                        </li>
                        <li class="m-nav__separator">-</li>
                        <li class="m-nav__item">
                            <a href="" class="m-nav__link">
                                <span class="m-nav__link-text">Home</span>
                            </a>
                        </li>
                        <li class="m-nav__separator">-</li>
                        <li class="m-nav__item">
                            <a href="" class="m-nav__link">
                                <span class="m-nav__link-text">Form Builder</span>
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

        <!-- END: Subheader -->
@using (Html.BeginForm("Data", "Home", FormMethod.Post))
{
        <div class="m-content">
            <div id="m_repeater_2">
                <div class="form-group  m-form__group row">
                    <div data-repeater-list="" class="col-12">
                        <div data-repeater-item class="form-group m-form__group row align-items-center">
                            <div class="col-md-3">
                                <div class="m-form__group m-form__group--inline">
                                    <div class="m-form__label">
                                        <label>Textbox:</label>
                                    </div>
                                    <div class="m-form__control">
                                        <input type="text" name="FullName" class="form-control m-input" placeholder="Enter full name">
                                    </div>
                                </div>
                                <div class="d-md-none m--margin-bottom-10"></div>
                            </div>
                            <div class="col-md-3">
                                <div class="m-form__group m-form__group--inline">
                                    <div class="m-form__label">
                                        <label class="m-label m-label--single">File Upload:</label>
                                    </div>
                                    <div class="m-form__control">
                                        <input type="file" name="Image" class="form-control m-input" placeholder="Enter contact number">
                                    </div>
                                </div>
                                <div class="d-md-none m--margin-bottom-10"></div>
                            </div>
                            <div class="col-md-3">
                                <div class="m-form__group m-form__group--inline">
                                    <div class="m-form__label">
                                        <label class="m-label m-label--single">Dropdown:</label>
                                    </div>
                                    <div class="m-form__control">
                                        <select class="form-control m-input" name="Dropdown" >
                                            <option value="value">Dropdown</option>
                                            <option value="value">Text 1</option>
                                            <option value="value">Text 2</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="d-md-none m--margin-bottom-10"></div>
                            </div>
                            <div class="col-md-2">
                                    <br />
                                <div class="m-checkbox-list mt-3">
                                    <label class="m-checkbox m-checkbox--state-success">
                                        <input type="checkbox" name="Active"> Checkbox
                                        <span></span>
                                    </label>
                                </div>
                            </div>
                            <div class="col-md-1">
                                <br />
                                <div data-repeater-delete="" class="btn-sm btn btn-danger m-btn m-btn--icon m-btn--pill">
                                    <span>
                                        <i class="la la-trash-o"></i>
                                        <span>Delete</span>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="m-form__group form-group row">
                    <div class="col-lg-4">
                        <div data-repeater-create="" class="btn btn btn-sm btn-brand">
                            <span>
                                <i class="la la-plus"></i>
                                <span>Add</span>
                            </span>
                        </div>
                        <input type="submit" value="Submit" />
                    </div>
                </div>
            </div>
        </div>
}
    </div>
</div>
<script>
    $("#m_repeater_2").repeater(
        {
            initEmpty: !1,
            defaultValues: { "text-input": "foo" },
            show: function () {
                $(this).slideDown()
            },
            hide: function (e) {
                confirm("Are you sure you want to delete this element?") && $(this).slideUp(e)
            }
        });

</script>
  

模型类

 public class FormBuilderModel
    {
        public string[] FullName { get; set; }
        public string[] Image { get; set; }
        public string[] Dropdown { get; set; }
        public bool[] Active { get; set; }
    }
  

控制器是

 [HttpPost]
        public ActionResult Data(FormBuilderModel model)
        {
            return View();
        }

0 个答案:

没有答案