I am completely new to ASP.Net and I am sure this is a very basic question I have a View in which there is a link to generate report but to be able to generate report I must ask the user to provide a suitable text name as well.
So far I have been able to pass data from server to view using Models passed from my controller to view, but I am not sure how to Pass data from view to my controller.
I just need to pass a string from view to controller in this case.
Any advice with example will be appreciated.
UPDATE
I understand I have to post the data back to server but how does that realize in the form of razorhtml code and controller?
This question is related to
asp.net
asp.net-mvc
In case you don't want/need to post:
@Html.ActionLink("link caption", "actionName", new { Model.Page }) // view's controller
@Html.ActionLink("link caption", "actionName", "controllerName", new { reportID = 1 }, null);
[HttpGet]
public ActionResult actionName(int reportID)
{
Note that the reportID in the new {} part matches reportID in the action parameters, you can add any number of parameters this way, but any more than 2 or 3 (some will argue always) you should be passing a model via a POST (as per other answer)
Edit: Added null for correct overload as pointed out in comments. There's a number of overloads and if you specify both action+controller, then you need both routeValues and htmlAttributes. Without the controller (just caption+action), only routeValues are needed but may be best practice to always specify both.
<form action="myController/myAction" method="POST">
<input type="text" name="valueINeed" />
<input type="submit" value="View Report" />
</form>
controller:
[HttpPost]
public ActionResult myAction(string valueINeed)
{
//....
}
Source: Stackoverflow.com