2016-12-05 114 views
1

我有两个控制器:交易及的CheckingAccountHtml.ActionLink发送Id参数到另一个控制器

在我指数鉴于支票帐户,我得到了以下内容:

<td> 
     @Html.ActionLink("Edit", "Edit", new { id=item.Id }) | 
     @Html.ActionLink("Details", "Details", new { id=item.Id }) | 
     @Html.ActionLink("Deposit", "Deposit", "Transaction",new {id = item.Id) | 
     @Html.ActionLink("Withdraw", "Withdraw", "Transaction", new { id = item.Id }) | 
     @Html.ActionLink("Delete", "Delete", new { id=item.Id }) 
    </td> 

编辑,细节和删除链接按其应有的原样工作,这意味着他们将Id链接发送到CheckingAccount控制器。

对于存款和取款链接,我想引导他们到具有相同ID的Transaction控制器。但是,它会再次指向CheckingAccount控制器。

我该如何解决这个问题?

回答

1

您应将其更改为:

<td> 
     @Html.ActionLink("Edit", "Edit", new { id=item.Id }) | 
     @Html.ActionLink("Details", "Details", new { id=item.Id }) | 
     @Html.ActionLink("Deposit", "Deposit", "Transaction",new {id = item.Id }, null) | 
     @Html.ActionLink("Withdraw", "Withdraw", "Transaction", new { id = item.Id }, null) | 
     @Html.ActionLink("Delete", "Delete", new { id=item.Id }) 
    </td> 

注意最后null参数。 ActionLink帮手有很多重载问题,所以没有null你基本上使用错误的重载,这就是为什么你没有得到你需要的链接。

这里是一个full answer

这里是你使用的是什么:

@Html.ActionLink(
    "Reply",             // linkText 
    "BlogReplyCommentAdd",         // actionName 
    "Blog",             // routeValues 
    new {              // htmlAttributes 
     blogPostId = blogPostId, 
     replyblogPostmodel = Model, 
     captchaValid = Model.AddNewComment.DisplayCaptcha 
    } 
) 

,这里是你应该使用什么:

@Html.ActionLink(
    "Reply",             // linkText 
    "BlogReplyCommentAdd",         // actionName 
    "Blog",             // controllerName 
    new {              // routeValues 
     blogPostId = blogPostId, 
     replyblogPostmodel = Model, 
     captchaValid = Model.AddNewComment.DisplayCaptcha 
    }, 
    null              // htmlAttributes 
) 
+0

谢谢。它有效,但为什么我们最后必须添加null? – Landowner

+0

错误的超载使用wilthot null –

+0

对不起。我无法得到。你能否详细说明一下? – Landowner

1

您可以将Id参数通过使用以下代码到另一个控制器:

@Html.ActionLink("Delete Data", "ActionName", "ControllerName", new { id = item.Id, },null) 
相关问题