@using System.Data
@model string

<div class="main">
    <form class="form-horizontal form ui-validForm" action="@Url.Action()" method="post">
        @foreach (DataRow dr in ViewBag.Fields.Rows)
        {
            if (dr["value_type"].ToString() == "ntext")
            {
                <div class="control-group">
                    <label class="control-label">@dr["name"].ToString()</label>
                    <div class="controls form-inline form-group-sm">
                        <textarea type="text" value="" class="form-control assignment" id="@dr["name"].ToString()" name="@dr["name"].ToString()" style="width:95%;height:300px;"></textarea>
                        <span class="help-block"></span>
                    </div>
                </div>
            }
            else
            {
                <div class="control-group">
                    <label class="control-label">@dr["name"].ToString()</label>
                    <div class="controls form-inline form-group-sm">
                        <input type="text" value="" class="form-control assignment" id="@dr["name"].ToString()" name="@dr["name"].ToString()" style="width:95%" />
                        <span class="help-block"></span>
                    </div>
                </div>
            }
        }

        <div class="control-group">
            <label class="control-label"></label>
            <div class="controls form-inline">
                <input type="hidden" class="form-control" id="collection_content" name="collection_content"/>
                <input type="hidden" id="id" name="id" value="{id}" />
                <button type="button" class="btn btn-primary btn-sm ui-pagePost" data-custom-params="url:'@Url.Action()',callBack:'PostRefreshBack',beforeExecute:'BeforeExecute'">提交</button>
                <button type="button" class="btn btn-default btn-sm ui-closeDialog">关闭</button>
                <span class="help-block"></span>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    @*var params = { valueField: 'id', textField: 'remark'};/*绑定表*/
    var listJson = CallAjax("get", false, "@Url.Action("ListData", "InfoTable")");
    $("#table_id").FillSelect(eval(listJson), params);*@

    //绑定数据
    var id = Request("id");
    if (id != "") {
        var data = @Html.Raw(Model??"null");
        $(".form").FormBind(data);
    }
    $(function () {
        var collection_content = $("#collection_content").val();
        var json = eval("(" + collection_content + ")");
        $(".assignment").each(function (j) {
            var id = $(this).attr("id");
            $("#" + id).val(eval("json[0]." + id));
        })
    })
    function BeforeExecute()
    {
        var collectionContent = "{";
        $(".assignment").each(function (j) {
            var id = $(this).attr("id");
            collectionContent += "\"" + id + "\":\"" + JsonFormat($("#" + id).val()) + "\",";
        })
        collectionContent = collectionContent.substring(0, collectionContent.length - 1) + "}";
        $("#collection_content").val(collectionContent);
        return true;
    }

</script>






