簡體   English   中英

C#MVC-返回PartialView不顯示整個頁面

[英]C# MVC - returning PartialView not showing the full page

我的控制器返回partialview時遇到問題。

這是我的控制器的外觀:

[HttpPost]
    public ActionResult ProcessSubmit(IEnumerable<HttpPostedFileBase> attachments, Models.FloorPlan.FloorPlanModel F)
    {
        F.FloorPlanList = null;
        if (ModelState.IsValid)
        {
            //if (Models.FloorPlan.Repository.FloorPlanMethods.AddFloorPlan(F))
            //{
                if (attachments != null && attachments.Count() == 1)
                {
                    foreach (var file in attachments)
                    {
                        // Some browsers send file names with full path. We only care about the file name.
                        var fileName = Path.GetFileName(file.FileName);
                        var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);

                        file.SaveAs(destinationPath);
                        F.Photo = destinationPath;
                        Models.FloorPlan.Repository.FloorPlanMethods.AddFloorPlan(F);
                    }
                }
            //}
        }
        Mvc.Models.FloorPlan.FloorPlanModel _floorPlanModel = new Models.FloorPlan.FloorPlanModel();
        _floorPlanModel.FloorPlanList = Mvc.Models.FloorPlan.Repository.FloorPlanMethods.GetFloorPlansAll(F.PropertyID);
        _floorPlanModel.PropertyID = F.PropertyID;

        return PartialView("~/Views/FloorPlan/Index.cshtml", _floorPlanModel);
        //return View("~/Views/FloorPlan/Index.cshtml", _floorPlanModel);
    }

這是我的視圖的樣子:

@model Web.CMS.Mvc.Models.FloorPlan.FloorPlanModel
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm("ProcessSubmit", "FloorPlan", FormMethod.Post, new { id = "uploadForm", encrypt = "multipart/form-data" }))
{
    @Html.ValidationSummary(false, "Please fix these errors.")

    <div class="H1">
    Floor Plans & Pricing
    </div>
    <!--<div class="iconAdd fl pt5 w120" onclick="FloorPlan_AddFloorPlan(); return false;">
        <a></a>
    </div>//-->
    <div class="fl clr" style="width: 600px;">
        <ul class="fl">
            <li class="w110">Name </li>
            <li class="w110">Beds </li>
            <li class="w110">Baths </li>
            <li class="w110">Sq Ft </li>
            <li class="w110">Price</li>
            <li class="w110">Text </li>
            <li class="w110">Photo </li>
        </ul>

        <ul class="fl">
            <li>@Html.TextBoxFor(f => f.Name)</li>
            <li>@Html.TextBoxFor(f => f.Bedrooms)</li>
            <li>@Html.TextBoxFor(f => f.Bathrooms)</li>
            <li>@Html.TextBoxFor(f => f.SquareFeet)</li>
            <li>@Html.TextBoxFor(f => f.Price)</li>
            <li>@Html.TextBoxFor(f => f.Body)</li>
            <li>@Html.TextBoxFor(f => f.Photo)
                @(Html.Telerik().Upload()
                    .Name("attachments")
                    .Multiple(false)
                )
                <div class="iconBrowse fr pt5"></div>
                <input type="submit" value="Send" class="t-button" />
                <input type="reset" value="Reset" class="t-button" />
            </li>
        </ul>
    </div>
    <br />
    <div class="clr">
    <input type="button" onclick="javascript: FloorPlan_AddFloorPlan(); return false;" value="Save" />
    @(Html.Telerik().Grid(Model.FloorPlanList)
            .DataKeys(k => k.Add(o => o.FloorPlanID))
            .DataBinding(dataBinding => dataBinding
                .Ajax()
                    .Select("Index", "Home")
                    .Delete("Delete", "FloorPlan"))
            .Name("FloorPlanListGrid")
            .Scrollable()
            .Pageable()
            .Selectable()
            .Columns(col =>
            {
                col.Bound(c => c.Name);
                col.Bound(c => c.Photo);
                col.Bound(c => c.Body);
                col.Bound(c => c.Bedrooms);
                col.Bound(c => c.Bathrooms);
                col.Bound(c => c.Price);
                col.Bound(c => c.SquareFeet);
                col.Command(commands =>
                {
                    commands.Delete();
                }).Width(100);
            })
        )
        @Html.HiddenFor(x => x.PropertyID)
    </div>  

}
<script src="@Url.Content("~/Scripts/floorplan.index.debug.js")" type="text/javascript"></script>

結果頁面僅包含View中“ Form”標記之后的實際數據。

這就是PartialViews的目的。 您調用一個返回局部視圖的動作。 如果在瀏覽器中查看頁面的源代碼,則不會看到元素。 如果要返回整頁,則需要使用return View(“ ......語句。這將使您在網站的“布局”頁面中查看。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM