Understanding action method execution:
Whenever first time request is coming to sample2 view the request will go to global.asax file check the action method name and control name then control will go to the that action method in the controller execute that action method lode them controller will be return view. After executing the view result will be delivered to client.
Even when user client on button also same action method will be called
If we want to call the other action method from the control we use the following procedure.
Learn more about ASP.net Interview Questions in this blog post.Interested in mastering ASP.net? Check out this blog post to learn more ASP.net Tutorials.
Step1: create action method with same name as view name with one argument of string type as button name
Function name is we find me action method like [accept verbs (http verbs.post)]
Public action result view name (string button name)
{
Code
Return view ();
}
àIn the above example to call the own action method from button “B1”, use the following steps
Go to home controller.cs
↓
Write the following code [accept verbs (http.verbs.post)]
Public action result sample2 (string B1)
{
View data [“a”] =”welcome sai”;
Return view ();
}
Go to sample2.aspx
Write the add the following code in the HTML form
<%: view data [“a”] %>
Run the application and check
For indepth understanding click on