我遇到了控制器返回部分视图的问题。
这就是我的控制器的样子:
[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>
结果页面仅包含我视图中“表单”标记之后的实际数据。
答案 0 :(得分:0)
这是PartialViews的用途。您调用一个返回局部视图的操作。如果您在浏览器中查看页面的来源,则既不会看到也不会看到元素。如果您想要返回整页,则需要使用返回视图(“...语句”。这将使您在网站的布局页面中查看。