Search code examples
asp.net-mvccontrollernullreferenceexceptionhttp-getepiserver

Episerver HttpGet method return null


I have a project that is based on the EpiServer MVC. One of PageContoller have a 2 methods:

    [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] method have this View:

    @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" />
}

But [HttpPost] argument is always null. Anybody knows, how the solve this problem?


Solution

  • So the problem in case is that Model implements IContent interface.Creating single ViewModel is solve this problem.