我嘗試創建一個asp.net mvc3應用程序。HttpPost編輯更新我的模型的動作
這是我的觀點:
@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工作!
我的參數是什麼?我的方法應該如何看待?
任何幫助,將不勝感激。
謝謝!
它會被表單發送嗎? – SLaks 2011-03-18 17:45:54
是的,它是由管理控制面板中的表單發佈 – user611684 2011-03-18 18:15:35
默認的模型聯編程序不應該處理這個嗎?在這種情況下: public ActionResult Edit(Iads.Elrams.Data.Entities.Page頁面) – WorldIsRound 2011-03-18 19:24:02