0
我有一個基於EpiServer MVC的項目。一個PageContoller的有2種方法:Episerver HttpGet方法返回null
[HttpGet]
public ActionResult Create()
{
var model = new Models.Comment {Time = DateTime.Now};
return View(model);
}
[HttpPost]
public ActionResult Create(Models.Comment comment)
{
if (comment != null)
{
CommentsContainer.Add(comment);
}
else
{
var x = new Models.Comment
{
User = "No user",
Body = "No text",
Time = DateTime.Now,
};
CommentsContainer.Add(x);
}
return RedirectToAction("Index");
}
[HTTPGET]法有這樣的觀點:
@using EPiServer.Globalization
@model EPiServer.Templates.Alloy.Models.Comment
@{
Layout = null;
}
@using (Html.BeginForm(null, null, new { language = ContentLanguage.PreferredCulture.Name }, FormMethod.Post))
{
@Html.LabelFor(model => model.User, "User")
@Html.EditorFor(model => model.User)
<br /><br />
@Html.LabelFor(model => model.Body, "Text")
@Html.EditorFor(model => model.Body)
<br /><br />
<input type="submit" value="Add" />
}
但[HttpPost]參數總是空。任何人都知道,如何解決這個問題?