Call an Action Method From View

空扰寡人 提交于 2019-12-24 05:07:25

问题


Here is the Action Method

[HttpGet]
[ViewException]
[UserFilter(OpUserAuthType.Admin, OpUserAuthType.Normal)]
public ActionResult YorumEkle(string id, string pid)
{
    .....
}

It has a view. But from another view, I want that action method to be called by an onclick event or anything to be clicked on. For instance:

<a href="" onclick="">Call YorumEkle Method</a>

回答1:


Use the ActionLink HtmlHelper like this...

@Html.ActionLink("Call YorumEkle Method", "YorumEkle", new {@id = "hello", @pid="yarg!"}, null))

It will generate the link you need.




回答2:


I can't comment but building on top of Cj's answer you can also specify which controller the action is on:

@Html.ActionLink("Link Text", "Action Name","Controller", new {@id = "hello", @pid="yarg!"}, null)

In your case

 @Html.ActionLink("Link Text", "YorumEkle","CvAramaController", new {@id = "hello", @pid="yarg!"}, null)


来源:https://stackoverflow.com/questions/20403416/call-an-action-method-from-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!