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]參數總是空。任何人都知道,如何解決這個問題?

回答

-1

所以問題就在於Model實現了IContent接口。創建單個ViewModel解決了這個問題。

0

你可以發佈你的模型類型的代碼?確保有用戶,正文和時間的公共屬性。