BootStrap Modal Popup需要很长时间才能加载

时间:2014-09-28 21:18:48

标签: asp.net-mvc-4 c#-4.0 twitter-bootstrap-3

我正在尝试使用BootStrap Pop Up将数据保存到数据库但是当我午餐时弹出它需要大约30秒加载,这是很多时间任何建议 这是我的代码

  @model  Medica.BusinessLayer.CompanyOrder
@{
    ViewBag.Title = Medica.Resources.Resources.ViewOrder;
    ViewBag.Header = Medica.Resources.Resources.ViewOrder;
    Layout = "~/Views/Shared/_LayoutPharmacy.cshtml";
    var culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name.ToLowerInvariant();
}

@helper selected(string c, string culture)
{
    if (c == culture)
    {
        @:checked="checked"
    }
}
<!-- modal placeholder-->
<div id='myModal' class='modal fade in'>
    <div class="modal-dialog">
        <div class="modal-content">
            <div id='myModalContent'></div>
        </div>
    </div>
</div>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary()

    <fieldset>
        <div>
            @Html.HiddenFor(model => model.ID)
            <div class="editor-label">

            </div>
            <div class="editor-field">
                @Medica.Resources.Resources.CompanyName :
                @Html.DisplayFor(model => model.Company.Name)
            </div>

            <div class="editor-field">
                @Medica.Resources.Resources.OrderNumber :
                @Html.DisplayFor(model => model.NO)
            </div>

            <div>
                @Medica.Resources.Resources.OrderStatus :
                @if (Model.StatusID == 1)
                {
                    <span class="label label-danger arrowed">@Html.DisplayFor(model => model.StringOrderStatus)</span>
                }
                else if (Model.StatusID == 2)
                {
                    <span class="label label-info arrowed-right arrowed-in">@Html.DisplayFor(model => model.StringOrderStatus)</span>
                }
                else if (Model.StatusID == 3)
                {
                    <span class="label label-success arrowed-in arrowed-in-right">@Html.DisplayFor(model => model.StringOrderStatus)</span>
                }
            </div>

            <div class="editor-field">
                @Medica.Resources.Resources.OrderDate :
                @Html.DisplayFor(model => model.DisplayDate)
            </div>
        </div>

        <div class="row" style="margin: 0;padding: 0px;" id="items">
            <div class="col-xs-12">
                <h3 class="header smaller lighter blue">@Medica.Resources.Resources.OrderItems</h3>
                <div class="table-header">
                    <i class="ace-icon fa fa-check green"></i><small>@Medica.Resources.Resources.CantFindItem @Html.ActionLink(@Medica.Resources.Resources.AddItem, "Add", "Item", new { }, new { data_modal = "", id = "btnCreate", @class = "my-class" })</small>
                    @if (Model.StatusID != 3)
                    {
                        @Html.ActionLink(@Medica.Resources.Resources.AddItem, "AddItem", "PharmacyBranchOrder", new { OrderID = Model.ID }, new { data_modal = "", id = "btnCreate", @class = "btn add_record" })
                    }
                </div>
                <div>
                    <div id="sample-table-2_wrapper" class="dataTables_wrapper form-inline" role="grid">
                        <div class="row">
                            <div class="col-xs-6">
                                <div id="sample-table-2_length" class="dataTables_length">
                                </div>
                            </div>
                            <div class="col-xs-6">
                                <div class="dataTables_filter" id="sample-table-2_filter">
                                </div>
                            </div>
                        </div>
                        <table id="sample-table-2" class="table table-striped table-bordered table-hover dataTable" aria-describedby="sample-table-2_info">
                            <thead>
                                <tr role="row">
                                    <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample-table-2" rowspan="1" colspan="1" aria-label="Domain: activate to sort column ascending">@Medica.Resources.Resources.ArabicName</th>

                                    <th class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample-table-2" rowspan="1" colspan="1" aria-label="Clicks: activate to sort column ascending">@Medica.Resources.Resources.LatinName</th>

                                    <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample-table-2" rowspan="1" colspan="1" aria-label="Update: activate to sort column ascending">
                                        <i class="ace-icon fa fa-clock-o bigger-110 hidden-480"></i>
                                        @Medica.Resources.Resources.RequiredQuantity
                                    </th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody role="alert" aria-live="polite" aria-relevant="all">

                                @foreach (var item in Model.CompanyOrderItems)
                                {
                                    <tr class="odd">
                                        <td class=" ">
                                            <a href="#">@Html.DisplayFor(modelItem => item.Item.ArabicName)</a>
                                        </td>
                                        <td class="hidden-480 ">@Html.DisplayFor(modelItem => item.Item.ItemLatinName)</td>
                                        <td class=" ">@Html.DisplayFor(modelItem => item.RequiredQuantity)</td>
                                        @if (Model.StatusID != 3)
                                        {
                                            <td class=" ">
                                                <div class="hidden-sm hidden-xs action-buttons">
                                                    <a class="blue">
                                                        @Html.ActionLink(@Medica.Resources.Resources.Edit, "EditItem", "PharmacyBranchOrder", new { id = item.ID }, new { data_modal = "" })
                                                    </a>
                                                    <a class="green">
                                                        @Html.ActionLink(@Medica.Resources.Resources.Delete, "DeleteItem", "PharmacyBranchOrder", new { id = item.ID }, new { data_modal = "" })
                                                    </a>
                                                </div>

                                                <div class="hidden-md hidden-lg">
                                                    <div class="inline position-relative">
                                                        <button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown" data-position="auto">
                                                            <i class="ace-icon fa fa-caret-down icon-only bigger-120"></i>
                                                        </button>

                                                        <ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
                                                            <li>
                                                                <a class="tooltip-info" data-rel="tooltip" title="" data-original-title="View">
                                                                    <span class="blue">
                                                                        @Html.ActionLink(@Medica.Resources.Resources.Edit, "EditItem", "PharmacyBranchOrder", new { id = item.ID }, new { data_modal = "" })
                                                                    </span>
                                                                </a>
                                                            </li>

                                                            <li>
                                                                <a class="tooltip-success" data-rel="tooltip" title="" data-original-title="Edit">
                                                                    <span class="green">
                                                                        @Html.ActionLink(@Medica.Resources.Resources.Delete, "DeleteItem", "PharmacyBranchOrder", new { id = item.ID }, new { data_modal = "" })
                                                                    </span>
                                                                </a>
                                                            </li>
                                                        </ul>
                                                    </div>
                                                </div>
                                            </td>
                                        }
                                    </tr>
                                }

                            </tbody>
                        </table>
                        <div class="row">
                            <div class="col-xs-6">
                                <div class="dataTables_info" id="sample-table-2_info">
                                    <i class="ace-icon fa fa-check green"></i><small> @Medica.Resources.Resources.Numberofitems @Model.CompanyOrderItems.Count.ToString()</small>                                    
                                </div> 
                            </div>
                            <div style="float:right;">
                                @if (Model.StatusID != 3)
                                {
                                    @Html.ActionLink(@Medica.Resources.Resources.Save, "Save", "PharmacyBranchOrder", new { OrderID = Model.ID }, new { @class = "btn add_record" })

                                    @Html.ActionLink(@Medica.Resources.Resources.Send, "Send", "PharmacyBranchOrder", new { OrderID = Model.ID }, new { @class = "btn add_record" })

                                    @Html.ActionLink(@Medica.Resources.Resources.Cancel, "Cancel", "PharmacyBranchOrder", new { OrderID = Model.ID }, new { @class = "btn add_record" })
                                }
                            </div>

                        </div>
                    </div>
                </div>
            </div>
    </fieldset>
}

<style>
    a.my-class {
        color: #333333;
    }

        a.my-class:active {
            color: #666666;
        }

        a.my-class:link {
            color: #999999;
        }

        a.my-class:visited {
            color: #CCCCCC;
        }
</style>


and that is my pop up View to add item to the order
@model Medica.ViewModel.CompanyOrderItemModel

@*<link href="~/Content/jquery-ui.css" rel="stylesheet" />*@
<link href="~/Content/style.css" rel="stylesheet" />

@{
    ViewBag.Header = Medica.Resources.Resources.AddOrderItem;
    Layout = null;
var culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name.ToLowerInvariant();
}

@helper selected(string c, string culture)
{
    if (c == culture)
    {
        @:checked="checked"
    }
}
<!-- modal placeholder-->
<div id='myModal' class='modal fade in'>
    <div class="modal-dialog">
        <div class="modal-content">
            <div id='myModalContent'></div>
        </div>
    </div>
</div>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">@Medica.Resources.Resources.AddItem</h4>
    </div>

    <div class="modal-body">
        @Html.HiddenFor(model => model.Item.CompanyOrderID)
        <div class="editor-label">
            @Medica.Resources.Resources.Item
        </div>
        <div class="editor-field">
            @Html.HiddenFor(model => model.Id)
            <input type="text" id="search" placeholder="Search for a product" required />
            @Html.ValidationMessageFor(model => model.Id)
        </div>

        <div class="editor-label">
            @Medica.Resources.Resources.RequiredQuantity
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Item.OrderItemRequiredQuantity)
            @Html.ValidationMessageFor(model => model.Item.OrderItemRequiredQuantity)
        </div>
    </div>

    <div class="modal-footer">
        <button class="btn" data-dismiss="modal">@Medica.Resources.Resources.Cancel</button>
        <input class="btn btn-primary" type="submit" value="@Medica.Resources.Resources.Add" />
    </div>
}
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/jqueryUI")

<script type="text/javascript">

    var url = '@Url.RouteUrl("DefaultApi", new { httproute = "", controller = "ItemApi" })';
    $('#search').autocomplete({

        source: function (request, response) {
            $.ajax({
                url: url,
                data: { query: request.term },
                dataType: 'json',
                type: 'GET',
                success: function (data) {
                    response($.map(data, function (item) {
                        return {
                            label: item.LatinName,
                            value: item.ID
                        }
                    }));
                }
            })
        }, position: {
            my: "right top",
            at: "right bottom"
        },
        select: function (event, ui) {
            $('#search').val(ui.item.label);
            $('#Id').val(ui.item.value);
            return false;
        },
        minLength: 3
    });
</script>




and that is the Controller 

 public class PharmacyBranchOrderController : BaseController
    {




[CustomAuthorize(Roles = "Pharmacy")]
        [HttpGet]
        public ActionResult Index(int ID)
        {
            MedicaEntities db = new MedicaEntities();
            CompanyOrder model = new CompanyOrder();
            model = OrderRepository.SelectOrderByID(ID);
            return View(model);
        }

        //[CustomAuthorize(Roles = "Pharmacy")]
        //[HttpPost]
        //public ActionResult Index(TestModel model)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        model.OrderItem.Item.CompanyOrderID = model.Order.ID;
        //        OrderRepository.AddNewCompanyOrderItem(model.OrderItem.Item);
        //        return RedirectToAction("Index", "PharmacyBranchOrder", new { id = model.Order.ID });

        //    }
        //    return View(model);
        //}

        [CustomAuthorize(Roles = "Pharmacy")]
        public ActionResult AddItem(int OrderId)
        {
            Medica.ViewModel.CompanyOrderItemModel model = new Medica.ViewModel.CompanyOrderItemModel();            
            model.Item = new CompanyOrderItem();
            model.Item.CompanyOrderID = OrderId;            
            return View(model);
        }

        [HttpPost]
        [CustomAuthorize(Roles = "Pharmacy")]
        [ValidateAntiForgeryToken]
        public ActionResult AddItem(Medica.ViewModel.CompanyOrderItemModel model)
        {
            if (ModelState.IsValid)
            {
                OrderRepository.AddNewCompanyOrderItem(model.Item);
                return Json(new { success = true });

            }
            else
            {
                ViewBag.Message = Medica.Resources.Resources.PleaseSelectTheItem;
                return RedirectToAction("AddItem", "PharmacyBranchOrder", new { OrderId = model.Item.CompanyOrderID });
            }
        }
}

任何人都可以帮我解决这个问题

0 个答案:

没有答案