【发布时间】:2014-11-19 22:29:56
【问题描述】:
我目前在使用以下 coden-ps 时遇到了一些问题,这些问题看起来与我几乎相同,但行为不同。
这些 sn-ps 来自我一直从事的两个不同项目,它们的构建方式相同,但只有一个可以正常工作。
这些是我输入控制器的表单:
表格 1,在 _Layout 文件中的 twitter 引导下拉菜单中:
@using (Html.BeginForm("EditProfile", "ProfilePage", FormMethod.Post))
{
<li>
<button type="submit" class="dropdownButton">Redigera Profil</button>
</li>
}
Form 2,尝试了不同的位置,但现在它位于 Block 视图中的表格中:
<td>
@using (Html.BeginForm("EditProfile", "ProfilePage", FormMethod.Post))
{
<button type="submit">Redigera profil</button>
}
</td>
两者看起来非常相似,对吧?
现在是控制器
控制器 1:
public ActionResult EditProfile(ProfilePage currentPage)
{
var model = new ProfilePageViewModel(currentPage);
model.CurrentUser = ConnectionHelper.GetUserInformationByEmail(User.Identity.Name);
return View("EditProfile", model);
}
控制器 2:
public ActionResult EditProfile(ProfilePage currentPage)
{
ProfilePageViewModel model = new ProfilePageViewModel(currentPage);
model.currentUser = ConnectionHelper.GetCurrentUserByEmail(User.Identity.Name);
return View("EditProfile", model);
}
也几乎相同。
我在两个项目中添加了相同的路由:
protected override void RegisterRoutes(RouteCollection routes)
{
base.RegisterRoutes(routes);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" });
}
现在问题来了:
表格 1 和控制器 1 工作正常,并且接收 ProfilePage currentPage 没有任何问题,但表格 2 和控制器 2 不起作用并获得空值。 正如我之前所说的,表格 1 发布在 _Layout 页面上,表格 2 发布在一个块中,该块在 mvc @section 中呈现。我不认为这是问题所在,因为我试图从页面的不同部分访问控制器,但它在任何地方都不起作用 - 但在另一个项目中,它无处不在,这让我发疯了。
有人知道为什么会这样吗?我在调试时已经对它们进行了调试,但唯一的区别是一个有效,另一个无效。
提前致谢
去性
编辑:
这里我渲染了一个叫做“内容”的部分,几乎所有的东西都会被渲染。
<div id="content">
@RenderBody()
@RenderSection("content", false)
</div>
我的起始页有一个用于块的 ContentArea,在此部分中呈现:
@model Intranet.Models.ViewModels.StartPageViewModel
@section content{
@if (User.Identity.IsAuthenticated)
{
<div class="contentArea">
@Html.PropertyFor(x => x.MainContentArea)
</div>
}
}
这里是继承自 BlockController 的控制器:
public class ProfileBlockController : BlockController<ProfileBlock>
{
public override ActionResult Index(ProfileBlock currentBlock)
{
ProfileBlockViewModel model;
if (currentBlock != null)
{
model = new ProfileBlockViewModel(currentBlock);
}
else
{
model = (ProfileBlockViewModel)Session["model"];
}
model.CurrentUser = ConnectionHelper.GetCurrentUserByEmail(User.Identity.Name);
var availableStatuses = ConnectionHelper.GetAllOfficeStatuses();
availableStatuses.Remove(model.CurrentUser.OfficeStatus);
model.AvailableStatusChanges = availableStatuses;
Session["model"] = model;
return PartialView(model);
}
}
【问题讨论】:
-
Controller 2ineherit from 是什么 -
两者都继承 ProfilePageController : PageController
-
该块是如何渲染的?通常一个块会由继承 BlockController 的控制器渲染?
-
是的,请检查我的编辑。
标签: c# asp.net-mvc episerver