【发布时间】:2011-03-18 17:40:15
【问题描述】:
我尝试创建一个 asp.net mvc3 应用程序。
这是我的看法:
@model Iads.Elrams.Data.Entities.Page
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<div class="formElement">
<div class="formFieldLabel">
@Html.LabelFor(model => model.ExternalLink)
</div>
<div class="formField">
@Html.TextBoxFor(model => model.ExternalLink, new { style = "width:400px" })
</div>
</div>
<div class="border content">
<div id="tabs" style="margin-top: 20px;"> <!-- jquery UI -->
<div class="tabMenu">
<ul>
@foreach (Iads.Elrams.Data.Entities.Language lang in ViewBag.Languages) {
<li><a href="#@lang.Iso2">@lang.Name</a></li>
}
</ul>
</div>
@{
foreach (Data.Entities.Language lang in ViewBag.AvailableLanguages) {
<div id="@lang.Iso2" class="border tabMenuContent">
<div class="formElement">
<div class="formFieldLabel">
@Html.LabelFor(model => model.GetTextOrDefaultByLang(lang.Iso2).Title) * <!-- Object: PageText -->
</div>
<div class="formField">
@Html.EditorFor(model => model.GetTextOrDefaultByLang(lang.Iso2).Title, new { style = "width:400px" })
</div>
</div>
<div class="formElement">
<div class="formFieldLabel">
@Html.LabelFor(model => model.GetTextOrDefaultByLang(lang.Iso2).NavText) *
</div>
<div class="formField">
@Html.EditorFor(model => model.GetTextOrDefaultByLang(lang.Iso2).NavText, new { style = "width:400px" })
</div>
</div>
</div>
}
}
</div>
<p>
<input type="submit" value="save" class="button" />
<input type="button" class="lightbutton" value="cancel" onclick="location.href = '@Url.RouteUrl(new RouteValueDictionary(new {
area = "Cms",
controller = "Page",
action = "Index"
}))';" />
</p>
</div>
}
这里是我的页面控制器:
public ActionResult Edit(int id) {
Page page = pageRepository.GetById(id);
if(page == null)
return new HttpNotFoundResult();
IEnumerable languages = languageRepository.GetAll();
languages = languages.OrderBy(m => m.LanguageId);
ViewBag.AvailableLanguages = languages;
return View(page);
}
[HttpPost]
public ActionResult Edit(what are the parameters???) {
// ?????
return View(page);
}
我希望将页面作为参数,但这不适用于 PageTexts!
我的参数是什么?我的方法应该如何?
任何帮助将不胜感激。
谢谢!
【问题讨论】:
-
是否通过表单发布?
-
是的,它是通过管理控制面板中的表单发布的
-
默认模型绑定器不应该处理这个吗?在这种情况下: public ActionResult Edit(Iads.Elrams.Data.Entities.Page page)
-
没有,因为有 x 个 PageTexts(每种语言一个)。它处理的页面属性,但不是 PageText 列表的属性。
标签: c# asp.net asp.net-mvc asp.net-mvc-3 razor