Sum*_*sht 0 asp.net-mvc mongodb razor
在索引中,我有以下链接用于要编辑的对象:
<div class="editor-field">@Html.ActionLink("Edit", "Edit", new { id = thing.Id })</div>
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我有以下方法签名:
public ActionResult Edit(Thing thing)
Run Code Online (Sandbox Code Playgroud)
但是没有调用,而是显示一个错误,指定传递空值.该链接包含对象所需的ID值.我是否需要更改控制器中Edit方法的签名?
更新:即使更改错误消息,示例也会失败
Server Error in '/' Application.
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'MongoDB.Bson.ObjectId' for method 'System.Web.Mvc.ActionResult Edit(MongoDB.Bson.ObjectId)'
Run Code Online (Sandbox Code Playgroud)
我是否需要更改控制器中Edit方法的签名?
是的,因为你只传递了一个id参数,你Html.ActionLink不能期望在你的Edit行动中获得更多的东西:
public ActionResult Edit(string id)
{
Thing thing = ... go and fetch the thing from the id
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
302 次 |
| 最近记录: |