0

我的控制器返回部分视图时遇到问题。

这是我的控制器的样子:

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

结果页面仅包含我的视图中“表单”标记之后的实际数据。

4

1 回答 1

0

这就是 PartialViews 的用途。您调用一个返回部分视图的操作。如果您在浏览器中查看页面的源代码,您将看不到 the 和元素。如果要返回完整页面,则需要使用 return View("... 语句。这将呈现您在站点的布局页面中的视图。

于 2012-07-06T23:17:41.297 回答