简体   繁体   English

C#MVC-返回PartialView不显示整个页面

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

I'm running into issues with my controller returning a partialview. 我的控制器返回partialview时遇到问题。

This is what my Controller looks like: 这是我的控制器的外观:

[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);
    }

This is what my View looks like: 这是我的视图的样子:

@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>

The resulting page only contains the actual data between the after the 'Form' tag in my View. 结果页面仅包含View中“ Form”标记之后的实际数据。

This is what PartialViews are for. 这就是PartialViews的目的。 You invoke an action which returns a partial view. 您调用一个返回局部视图的动作。 If you view the source of the page in a browser, you won't seen neither the nor the element. 如果在浏览器中查看页面的源代码,则不会看到元素。 If you want a full page to be returned, you need to use the return View("... statement instead. This will render you view within your site's Layout page. 如果要返回整页,则需要使用return View(“ ......语句。这将使您在网站的“布局”页面中查看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM