Ashkan
Ashkan

Reputation: 89

Call controller from view and pass value from view to controller in asp.net mvc

In view page, I have an html.actionlink: 1. How to call from html.actionlink, an actionresult name, that is inside the homecontroller(How to write the address of the controller and function, in actionlink?) 2. How to pass a number of variables from view\html.actionlink to homecontroller\actionresult? Thanks

Upvotes: 0

Views: 1091

Answers (2)

Janmejay Kumar
Janmejay Kumar

Reputation: 319

Html.ActionLink(article.Title, "ActionName", "ControllerName", new { id = article.ArticleID, title = article.Title }, null)

Upvotes: 1

MBARK T3STO
MBARK T3STO

Reputation: 339

I suggest you for passing some variables from View to controller/action to use this simple way :

submit button

So now whene you clicked in the button the form will be submit and will be pass the text value that have IH="test_var" to the action . Now in the controller we use this method to get the variable :

Imagin we have a controller that named controller inside this controller we use

Public actionresult simple_action (string test_var) {

//here you can write what you want to code

}

I wish this help you brother .

Upvotes: 0

Related Questions