ASP.NET MVC - Html.Action - 传递导致错误的DateTime数据

时间:2013-02-01 20:04:34

标签: asp.net-mvc asp.net-mvc-3 razor

我有这个:

@Html.Action("CheckForModifyPost", "Forums", new { postAuthor = item.Author.UserName, dateCreated = item.DateCreated})

我得到以下错误:

  

模型项传入   dictionary为null,但此字典需要非null模型项   类型为'System.Int32'。

item.Author.UserNameitem.DateCreated都不为空,我所知道的是这与item.DateCreated有关。我该如何解决这个错误?

1 个答案:

答案 0 :(得分:0)

suppose your controller is as follow

ForumController.cs
[httpGet]
public void CheckForModifyPost(string postAuthor, DateTime dateCreated )
{
  YOUR CODE GOES HERE
}



@Html.Action("CheckForModifyPost", "Forums", new { postAuthor = item.Author.UserName, dateCreated = item.DateCreated})



so in @html.Action pass the value with same name as in your action method like if in action method "postAuthor" as argument than in @html.Action pass the value of that argument with same name as in action method means use "postAuthor" in your @html.Action,
if their is only one character different than error occure