【问题标题】:I have a problem when I try to render a partial view in may main view当我尝试在可能的主视图中渲染部分视图时遇到问题
【发布时间】:2020-06-15 11:20:43
【问题描述】:

我有以下局部看法:

@model IDECOHealthInsurance.Models.Pharmacy
@using (Ajax.BeginForm("pharmacyDetials", "Pharmacy", new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "pDetail", InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace, LoadingElementId = "Loading", OnBegin = "" }))
{


<h4>تفاصيل الصيدلية</h4>

<div id="pDetail" class="MainGridContainer pb-5">

    @if (Model.dtItemsDetails != null)
    {

        <table dir="rtl" id="Paitents" class="MainGrid">
            <thead>
                <tr style="text-size-adjust:auto">

                    <th>
                        رقم الموظف
                    </th>
                    <th>
                        التاريخ
                    </th>
                    <th>
                        الوقت
                    </th>
                    <th>
                        المستفيدون
                    </th>
                    <th>
                        ملاحظات
                    </th>
                    <th>
                        الباركورد
                    </th>
                    <th>
                        أسم العينة
                    </th>
                    <th>
                        الكمية
                    </th>
                    <th>
                        السعر
                    </th>

                </tr>
            </thead>
            <tbody>

                @foreach (System.Data.DataRow row in Model.dtItemsDetails.Rows)
                {
                    <tr style="width:100%">

                        <td>
                            @row["EMPLOYEE_NUMBER"]
                        </td>
                        <td>
                            @row["ENTRY_DATE"]
                        </td>
                        <td>
                            @row["ENTRY_TIME"]
                        </td>
                        <td>
                            @row["BENEFICIARIES"]
                        </td>
                        <td>
                            @row["NOTE"]
                        </td>

                        <td>
                            @row["ITEM_CODE"]
                        </td>
                        <td>
                            @row["ITEM_NAME"]
                        </td>
                        <td>
                            @row["QTY"]
                        </td>
                        <td>
                            @row["PRICE"]
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    }
</div>
}

还有下面的控制器:

[HttpGet]

        public ActionResult pharmacyDetials(Pharmacy model)
        {
            var masterID = Convert.ToInt32(Session["login"]);
            if (masterID == 0)
            {
                return RedirectToAction("Login");
            }
            else
            {
                Models.Pharmacy objPharamcyMode = new Pharmacy();

                IDECOServiceReference.IdecoAPIServiceClient idecoAPI = new IDECOServiceReference.IdecoAPIServiceClient();
                DataTable dataTable = idecoAPI.GETPHARMACYEMPLOYEEMASTER("", 1);

                model.dtItemsDetails = dataTable;

                return PartialView("_PharmacyDetails", model);
            }
        }

以及以下主视图:

@model IDECOHealthInsurance.Models.Pharmacy

@{
    ViewBag.Title = "PharmacyApplication";
    Layout = "~/Views/Shared/_Layout.cshtml";

}

<table style="height:680px; width:1280px; border:hidden">
    <tr>
        <td>
            <div id="pDetail">          
                    @Html.Partial("_PharmacyDetails", Model)

                </div>
        </td>
        <td>

            @using (Ajax.BeginForm("PharmacyApplication", "Pharmacy", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "updatePnl", InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace, LoadingElementId = "Loading", OnBegin = "" }))
            {


                    <div class="form-horizontal">
                    <div class="form-group">
                        <div class="col-md-offset-2 col-md-10">
                            <input type="submit" id="panel" value="أضافة" class="btn btn-default" />
                        </div>

                        <input class="btn btn-default" type="button" value="خروج" onclick="@("window.location.href='" + @Url.Action("LogOut", "Pharmacy") + "'");" />
                    </div>

                </div>

            }
        </td>
    </tr>
</table>

<div id="updatePnl">
    @Html.Partial("_PartialPharmacyDetails", Model)
</div>
<br />
<br />
<br />

<div id="pnlItemsDetails">
    @Html.Partial("_PartialItemsDetails", Model)
</div>

当我尝试在主视图中呈现 _PharmacyDetails 时,它不会返回任何记录。问题是什么?以及我该如何解决?请向我解释这个问题是如何发生的。我做错了什么?

【问题讨论】:

    标签: asp.net-mvc model-view-controller asp.net-mvc-5


    【解决方案1】:

    我使用 Action 方法而不是使用 Partial 方法来渲染局部视图:

      <tr>
                <td>
                        <div id="pDetail" style="background-color:aliceblue" method="Get">
                            @Html.Action("pharmacyDetials", Model)
                        </div>
    
                    </td>
                <td>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多