I have this view which is not passing data to the controller. Why is this happening?
View:
@Html.DisplayFor(model => model.threadID)
@Html.ActionLink("Add Post", "CreatePost", "Threads", new { id = Model.threadID })
CreatePost Method in Threads Controller:
[HttpGet]
public ActionResult CreatePost(string id)
{
PostModel model = new PostModel(id);
return View(model);
}
The DisplayFor
in the view is diplaying the ID (string), however when calling the CreatPost method in the controller, the id being passed is null
我认为你使用了错误的重载方法,试试这个:
@Html.ActionLink("Add Post", "CreatePost", "Threads", new { id = Model.threadID }, null)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.