问题
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