动态生成的控件在回发MVC5时丢失

时间:2017-04-28 09:21:18

标签: asp.net-mvc kendo-ui asp.net-mvc-5

我创建了一个生成动态控件的MVC 5应用程序。回发时formcollection为null。我已在表格标签中附上表格。不确定是什么问题

以下是主要表格。 Clciking on submit没有回复formcollection

实际用户界面

enter image description here

包含菜单项的视图

@model IEnumerable<CC.GRP.BluePrismMenu.Models.BluePrismRequestCustomer>
@using Kendo.Mvc.UI;
@using (Html.BeginForm("MenuResult", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @*@Html.AntiForgeryToken()*@
    <div class="sidebar-nav k-content">
        @(Html.Kendo().Menu()
            .Name("nav")
            .BindTo(Model, mappings => {
                mappings.For<CC.GRP.BluePrismMenu.Models.BluePrismRequestCustomer>
            (binding => binding
            .ItemDataBound((item, requestCustomer) =>  {
                if (requestCustomer.Active == true) {
                    item.Text = requestCustomer.CustomerDisplayName;
                }
            })
            .Children(requestCustomer => requestCustomer.BluePrismRequestTypes));
                mappings.For<CC.GRP.BluePrismMenu.Models.BluePrismRequestType>
                    (binding => binding
                    .ItemDataBound((item, requestType) => {
                        if (requestType.CustomerID > 0) {
                            if (requestType.Active == true) {
                                item.Text = Convert.ToString(requestType.RequestTypeID) + "," + requestType.RequestTypeValue;
                            }
                        }
                    }));
            })
                .Orientation(MenuOrientation.Vertical)
                .Events(e => e.Select("menuItemSelect"))
        )
    </div>
}
<script type="text/javascript">
    var Cid = "";

    function menuItemSelect(e) {
        var Cname = "";
        var MSelect = $(e.item).children(".k-link").text();
        var fields = MSelect.split(",");
        if (fields[0] != null) {
            Cid = fields[0];
            Cname = fields[1];
        }
        $("#article").load("Home/MenuResult", { requestTypeID: Cid });
    }

    //function onClickPost() {
    //        $("#article").load("Home/Edit", { requestTypeID: Cid });
    //}

</script>
    <div id="article" class="article-div">
    </div>

包含动态控件的视图

   @model IEnumerable<CC.GRP.BluePrismMenu.Models.BluePrismRequestTypeConfig>
@{
    ViewBag.Title = "Blue Prism Submit Edit";
}
<hgroup class="title">
    <h1>@ViewBag.Title.</h1>
    <h2>@ViewBag.Message</h2>
</hgroup>
<BR />


@using (Html.BeginForm("Edit", "Home"))
    {
    <script type="text/javascript">
        function onClickPost() {
             $("#article").load("Home/Edit", {requestTypeID: Cid});
    }
    </script>



    @Html.AntiForgeryToken()
    <div class="form-horizontal" id="myform">
        <div class="row">
            <h4>Send Request @ViewBag.Header</h4>
        </div>
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <fieldset>
            <legend>Edit</legend>
            @foreach (var item in Model)
                {
                    switch (item.FieldType)
                    {
                        case "TEXT":

                        <div class="form-group row">
                            @Html.Label(item.FieldLable, htmlAttributes: new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @(Html.Kendo().TextBox().Name(item.FieldLable.Replace(" ", "-")))

                                @Html.ValidationMessage(item.FieldLable.Replace(" ", "-"), new { @class = "text-danger" })
                            </div>
                        </div>

                        break;
                    case "DATE":

                        <div class="form-group row">
                            @Html.Label(item.FieldLable, htmlAttributes: new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @(Html.Kendo().DatePicker().Name(item.FieldLable.Replace(" ", "-")).Format("dd/MM/yyyy"))
                                @Html.ValidationMessage(item.FieldLable.Replace(" ", "-"), new { @class = "text-danger" })
                            </div>
                        </div>

                        break;
                    case "NUMBER":

                        <div class="form-group row">
                            @Html.Label(item.FieldLable, htmlAttributes: new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @(Html.Kendo().NumericTextBox().Name(item.FieldLable.Replace(" ", "-")).Format("{0:n0}").Decimals(0))
                                @Html.ValidationMessage(item.FieldLable.Replace(" ", "-"), new { @class = "text-danger" })
                            </div>
                        </div>

                        break;
                }
            }
        </fieldset>
    </div>


    <br /><br />
    <div class="form-group row">
        <div class="col-md-offset-2 col-md-10">
            @(Html.Kendo().Button()
                .HtmlAttributes(new { type = "button" })
                .Name("textButton")
                .Icon("tick")
                .Content("Submit")
                .Events(ev => ev.Click("onClickPost"))
            )

            <a href="/CC.GRP.BluePrismMenu/" id="cancel">Clear</a>
            <script>jQuery(function () { jQuery("#cancel").kendoButton({ "icon": "cancel" }); });</script>
        </div>
    </div>
}

控制器

   [AcceptVerbs(HttpVerbs.Post)]
        //[ValidateAntiForgeryToken]
        public ActionResult Edit(int? RequestTypeID,  FormCollection fc)
        {
            ServiceReference1.ComputaCenterLoader1PortTypeClient Service = new ServiceReference1.ComputaCenterLoader1PortTypeClient();
            Service.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings.Get("userName");
            Service.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings.Get("Password");

            //var bluePrismRequestTypeConfig = db.BluePrismRequestTypeConfigs.Where(o => o.RequestTypeID == RequestTypeID && o.Active == true).ToList();

            BluePrismRequestType bluePrismRequestType = db.BluePrismRequestTypes.Find(RequestTypeID);

            StringBuilder builder = new StringBuilder();
            int count;
            builder.Length = 0;
            count = 0;
            foreach (var key in fc.Keys)
            {
                if (key.ToString() != "__RequestVerificationToken")
                {
                    count = count + 1;
                    if (count == 1)
                    {
                        builder.Append(fc[key.ToString()]);
                    }
                    else
                    {
                        builder.Append("," + fc[key.ToString()]);
                    }
                }
            }
            try
            {
                Service.Loader("auto", bluePrismRequestType.RequestTypeValue.ToString(), builder.ToString());
                TempData["Status"] = "Send successfully";
            }
            catch (SoapException error)
            {
                TempData["Status"] = error.Detail.ToString();
            }
            catch (Exception e)
            {
                TempData["Status"] = e.InnerException.Message.ToString();
            }

            BluePrismTraceMessage bluePrismTraceMessage = new BluePrismTraceMessage();
            bluePrismTraceMessage.TraceTime = DateTime.Now;
            bluePrismTraceMessage.USERID = WindowsIdentity.GetCurrent().Name;
            bluePrismTraceMessage.Message = "RequestType:" + bluePrismRequestType.RequestTypeValue + ";variable:" + builder.ToString();
            bluePrismTraceMessage.ResponseXML = TempData["Status"].ToString();

            db.BluePrismTraceMessages.Add(bluePrismTraceMessage);
            db.SaveChanges();
            Service.Close();
            return RedirectToAction("Index");
        }

0 个答案:

没有答案