简体   繁体   English

MVC查看未将数据传递给Controller

[英]MVC View not passing data to Controller

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: 线程控制器中的CreatePost方法:

[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 视图中的DisplayFor是双层ID(字符串),但是当在控制器中调用CreatPost方法时,传递的id为null

我认为你使用了错误的重载方法,试试这个:

@Html.ActionLink("Add Post", "CreatePost", "Threads", new { id = Model.threadID }, null)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM