@using PageAdmin.Utils;
@using PageAdmin.Common;
@{
    int detailId = ViewBag.DetailId;
    int fieldId = ViewBag.FieldId;
    int parentId = ViewBag.ParentId;
    string parentGuid = ViewBag.parentGuid;
    string subTable = ViewBag.Table;
    CurrentUser currentUser = ViewBag.CurrentUser;
    string actionName = "Add";
    if(detailId>0)
    {
        actionName = "Edit";
    }
    IEnumerable<dynamic> fieldDataList = Html.GetFieldList(subTable, actionName, currentUser, (FromEnum)ViewBag.From, true);
    string from = Request.QueryString["_from"];
    string guid = Html.Guid();

}
<script src="~/Incs/UEditor/ueditor.config.js" type="text/javascript"></script>
<script src="~/Incs/UEditor/ueditor.all.min.js" type="text/javascript"></script>
<div class="main">
    <form method="post" id="_form" class="form-group-sm form ui-validForm" enctype="multipart/form-data" data-custom-params="beforeSubmit:'BeforeSubmit'" data-source="@Model">
        @{
            string beforeSubmitJs = "";
            var data = new ViewDataDictionary();
            data.Add("currentUser", currentUser);
            data.Add("guid", guid);
            data.Add("detailId", detailId);
            data.Add("from", from);
            data.Add("i", 0);
            int i = 0;
            foreach (var row in fieldDataList)
            {
                data["i"] = i;
                beforeSubmitJs += row.BeforeSubmitJs;
                Html.RenderPartial("~/Areas/E/Views/CustomForm/FormPartial.cshtml", (object)row, data);
                i++;
            }
        }
        <div class="form-group">
            <div class="controls">
                @Html.AntiForgeryToken()
                <input type="hidden" name="_fieldId" value="@fieldId" />
                <input type="hidden" name="ParentId" id="ParentId" value="@parentId" />
                <input type="hidden" name="ParentGuid" id="ParentGuid" value="@parentGuid " />
                <input type="hidden" name="Id" id="Id" value="0" />
                <input type="hidden" name="Guid" id="Guid" value="@guid" />
                <input type="hidden" name="_SubtableType" id="_SubtableType" value="single" />
                <input type="hidden" name="_AttachmentFields" id="_AttachmentFields" value="@Html.GetAttachmentFields(subTable)" />
                <button type="button" class="btn btn-sm  btn-primary ui-pagePost" data-custom-params="url:'@Url.Action()',callBack:'PostBack'">提交</button>
                <button type="button" class="btn btn-sm btn-default ui-closeDialog">关闭</button>
            </div>
        </div>
    </form>

</div>
<script type="text/javascript">
     var field = "@StringHelper.FirstCharUpper(ViewBag.Field)";
    $("#_form").FormBind({ dataSourceFrom: "attr" });

    function BeforeSubmit() {
         @Html.Raw(beforeSubmitJs)
        return true;
    }

    function SetParent() {
        var recordCount = "1";
        var $parentFieldObj = parent.$("#" + field);
        var $parentFieldLbObj = parent.$("#_" + field + "_recordCount");
        if ($parentFieldObj.length > 0) {
            $parentFieldObj.val(recordCount);
            if ($parentFieldLbObj.length > 0) {
                $parentFieldLbObj.text(recordCount);
            }
        }
    }

    function PostBack()
    {
        SetParent();
    }
</script>
