我有一个基于EpiServer MVC的项目。PageContoller中的一个有两个方法:
[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参数总是空的。谁知道,怎么解决这个问题?
发布于 2015-04-08 07:13:02
因此,在这种情况下,模型实现了IContent interface.Creating,单ViewModel解决了这个问题。
发布于 2015-04-07 06:29:14
你能把模型类型的代码寄出去吗?确保用户、主体和时间都有公共属性。
https://stackoverflow.com/questions/29428377
复制相似问题